udjat
udjat

Reputation: 477

Using Recursion to Change a Variable

For a Binary Search Tree, I only have access to the root node, while I am trying to write a recursive method to dig into its left nodes.

For example,

root.left();

becomes

root.left().left();

and then,

root.left().left();

You see where this is going.. Is there a recursive way to change/add on to the variable?

Upvotes: 0

Views: 68

Answers (1)

Cyrille Ka
Cyrille Ka

Reputation: 15523

Something like this ?

Node node = root;
while (someCondition) {
    node = node.left();
    // do something with the node
}

Upvotes: 2

Related Questions