Can someone explain how do we create a level order binary tree.
I am unable to understand the code from GeeksforGeeks. Plz explain…
Can someone explain how do we create a level order binary tree.
I am unable to understand the code from GeeksforGeeks. Plz explain…
hello @sanjit_15
to construct a tree from level order , we perform level order traversal only .
look at this code.
this code is exaclty similar to level order traversal.
we pop node from q.
now we check whether its left node exist or not by checking value of c1 . it exist we create a new node and add it to the left of current node. and push that newly created node in q.
similarly we do for right node.
and at end when q get empty .
the tree construction is done and we return root of the tree
Can you plz tell how do I rectify the error, I just want to create and then output the level order tree using operation overloading ( >> & << ).
The link of my code:
pass it as a reference.
here as well
made the changes but still getiing this error :
/bin/run.sh: line 4: 18 Killed ./exe
your code is correct and running fine,
u r not giving input correclty thats why it is giving such error
It’s not compiling at all. I tried to run without giving any input…
If that is the case, can you tell how should i provide input. ?
What can we do to avoid giving -1 as input?
Prateek bhaiya gives the input without those -1’s…
bro we have to give -1 . because our buildtree algorithm is like that only.
it uses -1 to check whether node exist or not.
if bhaiya’s code is working without any -1 then probably he is implementing tree differently.
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.