how do i build the tree?
How to take build bt with level order input?
To create a binary tree from level order input, we can build this binary tree by maintaining a queue. Queue is used to maintain those nodes that are not yet processed.
Using a variable count to keep track of the number of children added for the current node.
First, create a root node, assign it as the current node. So starting from index 1 (index 0 is the root), as the count is 0, we add this node as left child of the current node. Increase count. If this node is not β-1β, add it to the queue.
Moving to the next index, the count is 1, so we add this as right child of current node, reset count to 0 and update current node (by assigning the current node as the first element in the queue). If this node is not β-1β, add it to the queue.
You can refer this sample code https://ide.codingblocks.com/s/60835
till when should i read input,I dont know the size of input array
-1 given input will take care of it. You donβt have to take an input array. Simply take the input from the user until user gives the input.