aboutsummaryrefslogtreecommitdiff
path: root/btree.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2021-11-23 06:20:24 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2021-11-23 06:20:39 +0000
commit516325444fc6e109e6fcb0afc895ca6434499c53 (patch)
treed8014527db09c112f3041ae501da8885804fe17f /btree.cpp
parent55a24fc5601e05c7dfad9149bc93ac44302f94ae (diff)
downloadalgorithms-516325444fc6e109e6fcb0afc895ca6434499c53.tar.gz
algorithms-516325444fc6e109e6fcb0afc895ca6434499c53.tar.bz2
algorithms-516325444fc6e109e6fcb0afc895ca6434499c53.zip
(btree)+basic main test for insert
Diffstat (limited to 'btree.cpp')
-rw-r--r--btree.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/btree.cpp b/btree.cpp
index 0ac794f..8c32b1f 100644
--- a/btree.cpp
+++ b/btree.cpp
@@ -3,6 +3,7 @@
* Author: Aryadev Chavali
*/
+#include <iostream>
enum Order
{
@@ -50,3 +51,27 @@ BinaryTree<T> *insert(BinaryTree<T> *tree, T value)
return tree;
}
+int main(void)
+{
+ auto tree = new BinaryTree<int>;
+ tree->value = 5;
+ tree->compare = [](int x, int y) {
+ if (x < y)
+ return LT;
+ else if (x > y)
+ return GT;
+ else
+ return EQ;
+ };
+
+ for (int i = 0; i <= 5; ++i)
+ {
+ tree = insert(tree, i * 2);
+ }
+
+ std::cout << tree->left->value << ", "
+ << tree->value << ", "
+ << tree->right->value << std::endl;
+ delete tree;
+ return 0;
+}