aboutsummaryrefslogtreecommitdiff
path: root/btree.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-11-23 06:10:55 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-11-23 06:14:06 +0000
commit8de4860e1d8a1db51e8dbdd12448312613390fc9 (patch)
tree89967610784e3c94ee0215b816f338fa7740ea3b /btree.cpp
parent855e38cde4fbc02fdcc9dbd47f2063cfe60a4b68 (diff)
downloadalgorithms-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.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/btree.cpp b/btree.cpp
index e5d412c..c22c297 100644
--- a/btree.cpp
+++ b/btree.cpp
@@ -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;
+ }
+};
+