You can do a zig-zag traversal of a tree by using 2 stacks in place of
the 2 queues you'd use for level order traversal.  As you do the zig-
zag traversal, just keep track of the current and previous node
visited and set previous->zznext = current at each visit.

On Dec 11, 1:52 am, AMAN AGARWAL <mnnit.a...@gmail.com> wrote:
> Hi,
>
> Given a tree, in addition to the left and right pointer, it has a third
> pointer, that is set to NULL.
> Set the third pointer to a node, which will be the successor of the current
> node, when the tree is traversed in the zig-zag order. In other words, if
> we traverse the tree using this third pointer alone, then we will be
> traversing the tree in the zig-zag order.
>
> Regards,
> Aman
>
> --
> AMAN AGARWAL
> "Success is not final, Failure is not fatal: It is the courage to continue
> that counts!"

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to