i have checked this code for many test cases and it is working fine. But still,4 out of 5 test cases are failing(run error)
. Can you please tell me what is missing or wrong in this code
I think i have written the code correct
@apoorvsingh27,
1
8
758 467 675 322 178 901 726 690
2
322 901
Your output: 758 467 675 322 178 726 690
Correct output: 758 467 178 675 726 690
Don’t use stack for input.
how does the input method affect the answer
@apoorvsingh27,
The tree being created for the input:
1
8
758 467 675 322 178 901 726 690
2
322 901
The correct preorder of tree is: 758, 467, 322, 178, 675, 726, 690, 901
your preorder tree of tree constructed is: 758 467 675 322 178 901 726 690
i assumed the given array is preorder traversal.
then we have to compare each element with all nodes and place according to its value(greater or less the parent) ?
please see this…now I have changed the code, now two test cases are running but still 3 are showing run error
@apoorvsingh27,
https://ide.codingblocks.com/s/226169 corrected code
I have added comments on the lines I have added.
A lot of cases were missing in the deletenode function when n1.left!=null &&n1.right==null and n1.left == null && n1.right != null.
The rest of the code is correct.
thank you very much for helping