print tree anticlockwise

Print all edge nodes of a complete binary tree anti-clockwise.
That is all the left most nodes starting at root, then the leaves left to right and finally all the rightmost nodes.
In other words, print the boundary of the tree.
Variant: Print the same for a tree that is not complete.
Assume we have a binary tree below:
    _30_
   /    \   
  10    20
 /     /  \
50    45  35
The correct solution should print 30, 10, 50, 45, 35, 20.

Comments

Popular posts from this blog