[algogeeks] Zig Zag tree traversal

2011-08-28 Thread Navneet Gupta
Print tree in zig zag manner 1 / \ 23 / \ / \ 4 56 7 O/P: 1 3 2 4 5 6 7 -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Zig Zag tree traversal

2011-08-28 Thread Yuchen Liao
You can use two stacks(A, B) when traversal. Use A as the stack when traveling the odd levels. B as the even levels. A.push(1); A.pop(); //1 //push the son of the node 1, from left to right; B.push(2); B.push(3); B.pop(); // 3 //push the son of the node 3, from right to left A.push(7);

Re: [algogeeks] Zig Zag tree traversal

2011-08-28 Thread KARTHIKEYAN V.B.
use one queue Enqueue all the nodes in normal level order traversal in the queue as 1 2 3 4 5 6 7 Each level contains 2 to the power n nodes in the queue. have two pointers ptr1 and ptr2 point ptr1 to the start node of 2 power n nodes range and ptr2 to the last node of this range. For odd