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 levels print nodes from ptr1 to ptr2

For even levels print nodes from ptr2 to ptr1

Keep count for odd and even levels so that it may be easy

This was my question in Microsoft Interview for Internship in the 2nd round.

But I too gave the solution using two stacks but the interviewer told me
this approach.

Regards,
Karthik.

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

Reply via email to