Data structures · real, tested code

Implement a Binary Search Tree in Larzscript

Insert values into a binary search tree and read them back in sorted order.

A deliberately simple, readable reference BST (no AVL/red-black self-balancing) - the point is seeing exactly how insert/inorder/height work, not raw performance.

larzscript pkg install tree

Code

import "tree" as bst

let t = bst.new()
for x in [5, 3, 8, 1, 4, 7, 9] { bst.insert(t, x) }
print(bst.inorder(t))
print(bst.contains(t, 4))
print(bst.height(t))
Output
[1, 3, 4, 5, 7, 8, 9]
true
2