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.
This commit is contained in:
2024-07-26 20:37:31 +01:00
parent 08e890ee4a
commit 096c1089ca

View File

@@ -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)
{