I know normal level order traversal of a binary tree,but in this what should I do reach on a certain level,how will I get to know the current level where I am at the moment.
Doubt in the concept
please check the code
@Adhyayan,
https://ide.codingblocks.com/s/221000 corrected code.
Few errors:
- Do addfirst instead of addlast.
- specify the type of LinkedList or what data your Linked list will hold.
- When c==0 we will add the left node instead of the right node.
- One of your brackets was at the wrong position, which terminated the while loop after first iteration.
Please reply on this thread if you have further doubts, else please mark this doubt as resolved.
Sir,in this question tree is starting from level 1 not from level 0 ???
@Adhyayan
We start from level 0 (root node)
Print the zig zag order i.e print level 1 from left to right, level 2 from right to left and so on. This means odd levels should get printed from left to right and even levels should be printed from right to left.
As given in the question. We keep count to check whether we should go from left to right or right to left
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.