0

Hey can anyone help me in this binary tree

Why i am not able to create two binary tree https://code.sololearn.com/cJPNW9uZV1Kt/?ref=app

12th May 2023, 1:29 PM
baibhav kumar
baibhav kumar - avatar
2 odpowiedzi
+ 3
root1 is null, probably because of line 29-32: if (idx>=nodes.length||nodes[idx] == -1) { return null; } What is your goal with this condition? What is the purpose of idx and why does it start with -1? Please tidy up your code and use proper indentation, because it is very difficult to see the structure of your program this way, especially since you have nested classes.
12th May 2023, 2:25 PM
Tibor Santa
Tibor Santa - avatar
0
Tibor Santa The purpose of if statement is to not print the -1after leaf node For example. If binary tree is 1,2,-1,-1 Here 2 is a leaf 🍃 node And that -1 is to start the index from 0 because of i++🤔
12th May 2023, 3:04 PM
baibhav kumar
baibhav kumar - avatar