Given a binary tree and a key, insert the key into the binary tree at first position available in level order

https://ide.codingblocks.com/s/196837 Help me with this. how to insert a node and where i am wrong

what you are doing here is simply building the tree normally, although u can build a height balanced tree during this operation itself by simply making the queue and inserting to the right and left the corresponding nodes, in the current node your queue has no effect, once the root is pushed, it’s right and left keep on getting pushed at one point if temp is pushed it’s left and right are NULL so NULL will get pushed and at the end of the node too it just prints the node and nothing else, does not alter the tree, this is more like a code for level order traversal, plus currently your tree is not getting built at all, take the values in a while loop and push to the left and then right if the value of d is -1 push null inside, that is how you should build the tree, for height balance simple take in the values all at once in an array and push one by one to left and right using the queue only u can do that if left is empty push there if right is empty push there and each time pop an element from the queue
i hope this solves your query

@Srajanjaiswal if your doubt is solved, please mark it as resolved