Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
____4 2 6 1 3 5 7 inorder (node) inorder(node.left) print(node.data) inorder(node.right) end We call the function, first time send the root as the argument it will call the function again with its left node 3 times and add the function to a stack frame. The third time is null so it returns. Now there are 2 calls left to return from After the return we print the data which is 1. Then it goes right, which is null, then returns. Now that function ended so we return from that frame. now we are on node.data = 2. We print it and go right. right has a 3, but we go left. it is null so we return, then print 3. Go right but it is null so we return and that function ends Now node.data = 2 ends so we return to 4. Print 4 then go right and the process is the same. We printed 1, 2, 3, 4. Practice printing the rest
8th Jan 2020, 5:21 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar