diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-11-23 06:10:55 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2021-11-23 06:14:06 +0000 |
commit | 8de4860e1d8a1db51e8dbdd12448312613390fc9 (patch) | |
tree | 89967610784e3c94ee0215b816f338fa7740ea3b /btree.cpp | |
parent | 855e38cde4fbc02fdcc9dbd47f2063cfe60a4b68 (diff) | |
download | algorithms-8de4860e1d8a1db51e8dbdd12448312613390fc9.tar.gz algorithms-8de4860e1d8a1db51e8dbdd12448312613390fc9.tar.bz2 algorithms-8de4860e1d8a1db51e8dbdd12448312613390fc9.zip |
(btree)+struct for binary tree
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.
Diffstat (limited to 'btree.cpp')
-rw-r--r-- | btree.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -4,3 +4,23 @@ */ +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; + } +}; + |