aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 20:37:31 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-07-26 20:46:34 +0100
commit096c1089ca5ff836c52fee95451480e0a293155b (patch)
tree8aa327c14194b96a97a436b2479b5dc95c6438be /src/main.cpp
parent08e890ee4ad21c9bfb0f0214923b675138ff1cd8 (diff)
downloadcw_tree-096c1089ca5ff836c52fee95451480e0a293155b.tar.gz
cw_tree-096c1089ca5ff836c52fee95451480e0a293155b.tar.bz2
cw_tree-096c1089ca5ff836c52fee95451480e0a293155b.zip
Helpers to get the rightmost and leftmost node
This, due to the properties of a cw tree, will be the largest and smallest fraction of the tree.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 87dec24..065f98a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -31,6 +31,22 @@
#define LINE_TOP (7 * HEIGHT / 16)
#define LINE_BOTTOM (9 * HEIGHT / 16)
+Node rightmost_node(const NodeAllocator &allocator)
+{
+ auto node = allocator.getVal(0);
+ while (node.right.has_value())
+ node = allocator.getVal(node.right.value());
+ return node;
+}
+
+Node leftmost_node(const NodeAllocator &allocator)
+{
+ auto node = allocator.getVal(0);
+ while (node.left.has_value())
+ node = allocator.getVal(node.left.value());
+ return node;
+}
+
int main(void)
{