This is for a red black tree.
For the pseudocode “p[z] <– y”, would the interpretation in java be:
z.getParent() = y;
or
z.setParent(y);
Thanks 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 valueyinto the result of callingz.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;