Level order zigzag problem


working for case 0 only

hello @bhattanurag426

we need to print in zig zag order.
ie first level from left to right
and then next level from right to left
then again next level from left to right
so on.

ur current code print only in left to right order

sir how to print in zig zag order

refer this->
We will be using 2 stacks to solve this problem. One for the current layer and other one for the next layer. Also keep a flag which indicates the direction of traversal on any level.

You need to pop out the elements from current layer stack and depending upon the value of flag push the childs of current element in next layer stack. You should maintain the output sequence in the process as well. Remember to swap the stacks before next iteration.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.