How to accept level order input?

How to accept level order input and build a BT.
1 2 3 4 5 6 -1 -1 -1 -1 -1 -1 -1

Level order input is taken and tree is build by using the queue, in which firstly u will take a queue of nodes, and then it will have a data which will represent a root node, and then u will accept the left and right child of root node, -1 value means that the node does not have any child.

U can refer to this code for your help :

2 Likes

Thanks a lot that is working, the explanation is also very clear :grinning: