Task

Implement a binary tree where each node carries an integer,   and implement:

   pre-order,
   in-order, 
   post-order,     and 
   level-order   traversal. 


Use those traversals to output the following tree:

         1
        / \
       /   \
      /     \
     2       3
    / \     /
   4   5   6
  /       / \
 7       8   9

The correct output should look like this:

preorder:    1 2 4 7 5 3 6 8 9
inorder:     7 4 2 5 1 8 6 9 3
postorder:   7 4 5 2 8 9 6 3 1
level-order: 1 2 3 4 5 6 7 8 9



See also

   Wikipedia article:   Tree traversal.


(
  ( tree
  =   1
    .   (2.(4.7.) (5.))
        (3.6.(8.) (9.))
  )
& ( preorder
  =   K sub
    .     !arg:(?K.?sub) ?arg
        & !K preorder$!sub preorder$!arg
      |
  )
& out$("preorder:   " preorder$!tree)
& ( inorder
  =   K lhs rhs
    .   !arg:(?K.?sub) ?arg
      & (   !sub:%?lhs ?rhs
          & inorder$!lhs !K inorder$!rhs inorder$!arg
        | !K
        )
  )
& out$("inorder:    " inorder$!tree)
& ( postorder
  =   K sub
    .     !arg:(?K.?sub) ?arg
        & postorder$!sub !K postorder$!arg
      |
  )
& out$("postorder:  " postorder$!tree)
& ( levelorder
  =   todo tree sub
    .   !arg:(.)&
      |   !arg:(?tree.?todo)
        & (   !tree:(?K.?sub) ?tree
            & !K levelorder$(!tree.!todo !sub)
          | levelorder$(!todo.)
          )
  )
& out$("level-order:" levelorder$(!tree.))
& 
)