0
Can anyone help me with an explanation for these codes ?
These methods are from binary tree implementation code and prints input data in order. I just don't understand this part. How these methods works ? public void inOrder(){ inOrder(root); } public void inOrder(Node akar){ if(akar != null){ inOrder(akar.left); System.out.print(akar.data+" "); inOrder(akar.right); } }
2 Antworten
+ 7
Poe firstly in order traversal is worked in LRR manner first left subtree is visited and printed then root is visited and printed then right subtree is visited and printed
when inOrder() method is called according to your posted code if the value of any occurred node "akar" is null then no node is present in tree or no any node is visited yet. So it first start visiting left node via inOrder(akar.left) and then inOrder(root) is traversed then inOrder(akar.right) is traversed and printed.
0
Thx for the explaination bro
so it can be functioned as a loop to traverse and print the visited node, am i right ?