next node: IndexingOfTrees,
prev node: TreeZip,
up to node: Subsystem Binary Trees


TreeConv

Trees can can be converted

Signature of TreeConv

List of Import References :
See BOOL
See Char
See DENOTATION
See Nat
See Option
See Seq
See String
See Tree

SIGNATURE TreeConv[data]

$Date: 2010-09-30 18:24:17 +0200 (Do, 30. Sep 2010) $ ($Revision: 616 $)

IMPORT Tree[data] ONLY tree
       Seq[data] ONLY seq
       Seq[seq[data]] ONLY seq
       String ONLY string

Parameter

SORT data

Converting into Textual Representation

Trees are represented as follows:

empty trees
are translated to "[/\]"
leaves
are translated to "[/data\]"
other trees
are represented as "[/data,left child,right child\]"
FUN ` : (data -> denotation) -> tree[data] -> denotation
FUN ` : (data -> string)     -> tree[data] -> string

These functions produce a twodimensional output of the tree. This works only for fixed width fonts, of course. The output assumes arbitrarily long lines. The function aborts, if one representation has zero length.

FUN graphic : (data -> denotation) -> tree[data] -> denotation
FUN graphic : (data -> string    ) -> tree[data] -> string

Converting into a Sequence

There are three possibilities: you can get the datas either in inorder -- left/node/right, in preorder -- node/left/right, or in postorder -- left/right/node.

FUN asSeqIn  asSeqPre asSeqPost : tree[data] -> seq[data]

asSeqBreadth gives you a sequence of sequence of datas. The ith element of the sequence contains all elements of level i from left to right.

FUN asSeqBreadth : tree[data] -> seq[seq[data]]


next node: IndexingOfTrees,
prev node: TreeZip,
up to node: Subsystem Binary Trees