From 096c1089ca5ff836c52fee95451480e0a293155b Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 26 Jul 2024 20:37:31 +0100 Subject: 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. --- src/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) { -- cgit v1.2.3-13-gbd6f