What is the interpretation of "p[z] <-- y" pseudocode in java?

Go To StackoverFlow.com


This is for a red black tree.

For the pseudocode "p[z] <-- y", would the interpretation in java be:

z.getParent() = y;



Thanks :)

2012-04-04 02:40
by copperhead4750


The correct code would be z.setParent(y);

Be aware that z.getParent() = y; is invalid code. The assignment operator = stores the result of evaluating the expression to the right of the = into a variable, attribute or array position to the left of the =. In an expression like the first one in your question, you'd be trying to assign the value y into the result of calling z.getParent() - that is, trying to assign a value into another value, and that won't work.

The right way to change an attribute is by calling the corresponding setXXX() method, or by directly assigning to the attribute if it was declared non-private, like this: z.parent = y;

2012-04-04 02:43
by Óscar López