I've had a question to doubly linked lists in Java yesterday, and there was a confusing comment to this part of my code
public ADList<K,D> split(K key){
// caching the current list
ADList<K, D> temp = this;
// looking for the key k to be split on
while(temp.head.key != key && temp.head.succ != null){
temp.head = temp.head.succ;
}
...
}
Here, I've saved the current instance of the doubly linked list which the method is called on, to look for the node with the key that is passed to the function. I've done this so that the list of the current instance does not get modified.
But I was told that this is wrong, and that the copy temp is not really a copy of the list, but actually a copy of the pointer to the list of the current instance. Which would mean that the function would alter the current instance instead of the copy.
Am I wrong, or has that person confounded Java with C? (lol) I'd really appreciate some insight :) thanks a bunch!