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.
gen_label(
?Index,
+Tree,
?Label)
get_label/3
instead if Index is instantiated.
get_label(
+Index,
+Tree,
?Label)
list_to_tree(
+List,
-Tree)
get_label(
K,
Tree,
Lab)
iff Lab is the
Kth element of List.
map_tree(
:Pred,
+OldTree,
-NewTree)
put_label(
+I,
+OldTree,
+Label,
-NewTree)
put_label(
+I,
+OldTree,
?OldLabel,
-NewTree,
?NewLabel)
tree_size(
+Tree,
?Size)
tree_to_list(
+Tree,
?List)
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.