> a = t 1 [ t 2 [ s 3, t 4 [s 5, s 6]]]
Tree 1 [Tree 2 [Tree 3 [],Tree 4 [Tree 5 [],Tree 6 []]]]
> removeSubtree 3 a |> Maybe.andThen (removeSubtree 5)
Just (Tree 1 [Tree 2 [Tree 4 [Tree 6 []]]])> a = t 1 [ t 2 [ s 3, t 4 [s 5, s 6]]]
Tree 1 [Tree 2 [Tree 3 [],Tree 4 [Tree 5 [],Tree 6 []]]]
> moveSubtree 4 1 a
Just (Tree 1 [Tree 2 [Tree 3 []],Tree 4 [Tree 5 [],Tree 6 []]])Compute the smallest subtree of the given tree which contains all the nodes of the nodeList.
> a = t 1 [ t 2 [ s 3, t 4 [s 5, s 6]]]
Tree 1 [Tree 2 [Tree 3 [],Tree 4 [Tree 5 [],Tree 6 []]]]
> spanningTree [3, 5] a
Just (Tree 2 [Tree 3 [],Tree 4 [Tree 5 [],Tree 6 []]])The function
attachSubtreeInOrder bigger targetNode subTree treeseeks to attach a subtree to a given tree is such a way that the parent of the subtree has the proper order with respect to the function
bigger : a -> a -> Boolnamely,
it is greater than the root of the subtree
it is greater than or equal to targetNode
it is the least such node
Here is an example:
> a = t 1 [ t 2 [ s 3, t 4 [s 5, s 6]]]
> Tree 1 [Tree 2 [Tree 3 [],Tree 4 [Tree 5 [],Tree 6 []]]]
> x = t 3 [ s 4, s 5]
> Tree 3 [Tree 4 [],Tree 5 []]
> attachSubtreeInOrder (<) 6 x a
> Just (Tree 1 [Tree 2 [Tree 3 [],Tree 4 [Tree 5 [],Tree 6 []],Tree 3 [Tree 4 [],Tree 5 []]]])> a = t 1 [ t 2 [ s 3, t 4 [s 5, s 6]]]
> depth a
3Number of notes in a tree
> a = t 1 [ t 2 [ s 3, t 4 [s 5, s 6]]]
> nodeCount a
6Transforms a tree of items into
a tree of tuples of the form (a, k), where k is the
depth of a in the tree.
> a = t 1 [ t 2 [ s 3, t 4 [s 5, s 6]]]
> tagWithDepth a
> Tree (1,0) [Tree (2,1) [Tree (3,2) [],Tree (4,2) [Tree (5,3) [],Tree (6,3) []]]]