Has a custom enum for ordering, as each type of data may have its own comparator system. Hence, each node will have a comparison function pointer internally. Though this increases the data required to create a binary tree, it does make it easier to support multiple types.
27 lines
278 B
C++
27 lines
278 B
C++
/* btree.cpp
|
|
* Date: 2021-11-22
|
|
* Author: Aryadev Chavali
|
|
*/
|
|
|
|
|
|
enum Order
|
|
{
|
|
LT,
|
|
GT,
|
|
EQ
|
|
};
|
|
|
|
template <typename T>
|
|
struct BinaryTree
|
|
{
|
|
T value;
|
|
BinaryTree<T> *left, *right;
|
|
enum Order (*compare)(T, T);
|
|
~BinaryTree()
|
|
{
|
|
delete left;
|
|
delete right;
|
|
}
|
|
};
|
|
|