Next: , Previous: Binary tree allocation, Up: Binary trees


14.3 Counting nodes and depth in a binary tree

— Function: int bst_valid_p (const Bstree *bst)

Returns non-zero iff the memory referenced by bst represents a valid bstree.1

— Function: ssize_t bst_nodes (const Bstree *bst)

Counts the number of nodes in bst.

— Function: ssize_t bst_depth (const Bstree *bst)

Calculates the depth of bst. The depth of a tree is one greater than the maximum of the depths of either of its subtrees; if a tree is empty, its depth is zero.


Footnotes

[1] The current implementation is merely a stub which always returns 1. This will change in a future release of Libretto.