Mikky
Mikky

Reputation: 345

B-Tree- method inorder(TreeNode<E> root)

I don't understand this method.

 protected void inorder(TreeNode<E> root) {
  if (root == null) return;
   inorder(root.left);
   System.out.print(root.element + " ");
   inorder(root.right);
}

When current node comes to last node in the tree and current.left become null, what then happened? current node returns where? When that node is going to print?

Upvotes: 2

Views: 662

Answers (1)

Ivaylo Strandjev
Ivaylo Strandjev

Reputation: 70929

If root.left is null, the function call inorder(root.left); will do nothing but return immediatley and then you will continue on with root and its right subtree.

Upvotes: 1

Related Questions