Only 2 testcases are passed

Try for this input
50 true 290 true 12 false false false true 75 true 62 false false true 80 false false
correct output : 50 75 290 12 62 80
your code gives:
50 75 290 12 80 62

you are doing wrong
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.

No Abha My output is same as provided by you for given input.