Next: bst bnodes iterating post-order, Previous: bst bnodes iterating in-order, Up: bst bnodes iterating [Index]
Pre–order iteration: visit the current node then the left child then the right child. As example, given the tree:
5-------10----12 | | | 1--3--4 7--9 11 | | | 2 6 8
the pre–order iteration is:
forward: 5, 1, 3, 2, 4, 10, 7, 6, 9, 8, 12, 11 backward: 5, 10, 12, 11, 7, 9, 8, 6, 1, 3, 4, 2
the forwards iteration is a “worm that always turns right”, while the backwards iteration is a “worm that always turns left”.
The following syntactic bindings are exported by the library
(vicare containers binary-search-trees)
. The bindings whose
name is prefixed with $
are unsafe operations: they do
not validate their arguments before accessing them.
Like fold-left
for lists, visit the nodes of a binary tree
with a pre–order forwards iteration. The argument root must be
#f
to represent an empty tree or an instance of
<binary-node>
representing the root of a tree.
Perform the first step in a pre–order forwards iteration. The argument
root must be #f
to represent an empty tree or an instance of
<binary-node>
representing the root of a tree. If the tree is
empty: return #f
; otherwise return an instance of
<binary-node>
representing the first visited node.
Advance an pre–order forwards iteration by one step starting from
bnode, which must be an instance of <binary-node>
. If
bnode is the last in the iteration: return #f
; otherwise
return an instance of <binary-node>
representing the next
visited node.
Like fold-right
for lists, visit the nodes of a binary tree with
a pre–order backwards iteration. The argument root must be
#f
to represent an empty tree or an instance of
<binary-node>
representing the root of a tree.
Perform the first step in a pre–order backwards iteration. The argument
root must be #f
to represent an empty tree or an instance of
<binary-node>
representing the root of a tree. If the tree is
empty: return #f
; otherwise return an instance of
<binary-node>
representing the first visited node.
Advance an pre–order backwards iteration by one step starting from
bnode, which must be an instance of <binary-node>
. If
bnode is the last in the iteration: return #f
; otherwise
return an instance of <binary-node>
representing the next
visited node.
Next: bst bnodes iterating post-order, Previous: bst bnodes iterating in-order, Up: bst bnodes iterating [Index]