Okay so I'm reading some code about RedBlackTrees. And I noticed this line "v1 = v2 = v3 = v4;" and I understand something like "v1 += v2" (add v2 to the current value of v1) and "v1 = v2" (create a reference from v2 to v1) etc.
public void insert( AnyType item )
{
current = parent = grand = header;
But I'm curious to what is happening in the memory/references with current = parent = grand = header;
http://faculty.washington.edu/moishe/javademos/REDBlack/RedBTree.java
Edit : 10:46 PM
I still have to wait 10 minutes to approve questions, sorry for the wait ladies and gents.
The reference value of header gets assigned to each of current, parent and grand. Basically all the variables would refer to the same thing.
By the way, this practice is often frowned up on in real life programming.
Consider what would happen if you had code like this:
boolean flag = false;
if(flag = true) {
System.out.println("true");
} else {
System.out.println("false");
}
The output would be true here as what's really happening here is an assignment rather than a comparison.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With