can u please process the sample input for me I mean how the tree will be formed using the input, I m having difficulty in understanding the
Level Order zig zag
First Take input for the root node.
Then take input for left subtree if exists.
Then take input for right subtree if exists.
Code:
public Node takeInput(Node parent, boolean ilc) {
//take input of data
Node child = new Node(data)
// left
boolean left = scn.nextBoolean();
if (left) {
child.left = takeInput(child, true);
}
// right
boolean right = scn.nextBoolean();
if (right) {
child.right = this.takeInput(child, false);
}
// return
return child;
}
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.