From 8de4860e1d8a1db51e8dbdd12448312613390fc9 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 23 Nov 2021 06:10:55 +0000 Subject: (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. --- btree.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'btree.cpp') 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 +struct BinaryTree +{ + T value; + BinaryTree *left, *right; + enum Order (*compare)(T, T); + ~BinaryTree() + { + delete left; + delete right; + } +}; + -- cgit v1.2.3-13-gbd6f