Go to the previous, next section.

Updatable Binary Trees

This package uses binary trees to represent arrays of N elements where N is fixed, unlike library(arrays). To load the package, enter the query

| ?- use_module(library(trees)).

Binary trees have the following representation: t denotes the empty tree, and t(Label,Left,Right) denotes the binary tree with label Label and children Left and Right.

@
Label labels the Index-th element in the Tree. Can be used to enumerate all Labels by ascending Index. Use get_label/3 instead if Index is instantiated.

@
Label labels the Index-th element in the Tree.

@
Constructs a binary Tree from List where get_label(K,Tree,Lab) iff Lab is the Kth element of List.

@
OldTree and NewTree are binary trees of the same shape and Pred(Old,New) is true for corresponding elements of the two trees.

@
Constructs NewTree which has the same shape and elements as OldTree, except that the I-th element is Label.

@
Constructs NewTree which has the same shape and elements as OldTree, except that the I-th element is changed from OldLabel to NewLabel.

@
Calculates as Size the number of elements in the Tree.

@
Is the converse operation to list_to_tree/2. Any mapping or checking operation can be done by converting the tree to a list, mapping or checking the list, and converting the result, if any, back to a tree.

Go to the previous, next section.