aboutsummaryrefslogtreecommitdiff
path: root/doc/ref/general/bst.texi
blob: d2bba0ffa67d927aebb7b4438bb6fb83ea0cb538 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@node Binary Search Tree
@section Binary Search Tree

A simple ``read only'' binary search tree.

@defun make-tree pred? lst
Constructs a new tree. @var{pred?} should be a procedure taking the
first element of @var{lst}, along with each element, and should return
a boolean value indicating if the specific element should go in the
left or right subtree. (left subtree is ``truthy'' values).

This operation is done recursively.
@end defun

@defun tree-node tree
Return the value of a tree node.
@end defun

@defun left-subtree tree
Return all ``truthy'' children of tree node.
@end defun

@defun right-subtree tree
Return all ``falsy children of tree node.
@end defun

@defun length-of-longest-branch tree
Get the depth of a tree.
@end defun

@defun tree-map proc tree
Apply proc onto the value of every node in tree, keeping the structure
of the tree.

@b{Note:} this can cause the tree to no longer be a binary search
tree, but simply a ``formless'' binary tree.
@end defun