Previous: , Up: bst bnodes iterating   [Index]


41.2.6.6 Iteration thunks

Iteration thunks are procedures accepting no arguments and returning an item from a collection; when the iteration finishes: the return value is the void object. Iteration thunks can be used with the facilities of the library (vicare containers iteration-thunks) (see iteration thunks). The following syntactic bindings are exported by the library (vicare containers binary-search-trees).

Function: make-binary-tree-forwards-in-order-iteration-thunk root
Function: make-binary-tree-backwards-in-order-iteration-thunk root

Build and return an iteration thunk visiting the node of a tree with a in–order forwards or backwards iteration. root must be #f to represent an empty tree or an instance of <binary-node> representing the root of a tree.

Here is an example with the fixnum trees defined in the introduction (see bst intro):

(import (vicare containers iteration-thunks))

(define root
  ;; 5-------10----12
  ;; |        |     |
  ;; 1--3--4  7--9 11
  ;;    |     |  |
  ;;    2     6  8
  (tree 5 1 3 2 4 10 7 12 6 9 8 11))

(iteration-thunk-fold
    (lambda (knil node)
      (cons (<fixnum-node>-sort-key node) knil))
  '()
  (make-binary-tree-forwards-in-order-iteration-thunk root))
⇒ (12 11 10 9 8 7 6 5 4 3 2 1)
Function: make-binary-tree-forwards-pre-order-iteration-thunk root
Function: make-binary-tree-backwards-pre-order-iteration-thunk root

Build and return an iteration thunk visiting the node of a tree with a pre–order forwards or backwards iteration. root must be #f to represent an empty tree or an instance of <binary-node> representing the root of a tree.

Function: make-binary-tree-forwards-post-order-iteration-thunk root
Function: make-binary-tree-backwards-post-order-iteration-thunk root

Build and return an iteration thunk visiting the node of a tree with a post–order forwards or backwards iteration. root must be #f to represent an empty tree or an instance of <binary-node> representing the root of a tree.

Function: make-binary-tree-forwards-level-order-iteration-thunk root
Function: make-binary-tree-backwards-level-order-iteration-thunk root

Build and return an iteration thunk visiting the node of a tree with a level–order forwards or backwards iteration. root must be #f to represent an empty tree or an instance of <binary-node> representing the root of a tree.

Function: make-binary-tree-forwards-breadth-first-iteration-thunk root
Function: make-binary-tree-backwards-breadth-first-iteration-thunk root

Build and return an iteration thunk visiting the node of a tree with a breadth–first forwards or backwards iteration. root must be #f to represent an empty tree or an instance of <binary-node> representing the root of a tree.


Previous: , Up: bst bnodes iterating   [Index]