There's something bugging me in the past 2 days. In Doubly Linked Lists, when will a Node get comepletely deallocated? is it when both Next and Previous references points to NULL? forget about the class and the method remove() and such.
Let me make an example so you get what I mean,
// Let's say we have this DLList. [1,2,3,4,5] and we make it a circular like this head.prev = tail; tail.next = head; //Now //If I do the following: head.next.next.next = head.prev; //That will points to 5 not 4 anymore. But does it mean 4 still not removed? //If I write another line: head.prev.prev.info() // info() or whatever method to print the element , why do I get 4??
My understanding is that a Node get deallocated by the garbage collecter automatecly when there is at least 1 reference is removed. is that right? correct me if I'm wrong.
I haven't dealt with Doubly Linked list that much. That's why I'm confiused. This deallocating thing always comes to my mind when I deal with Linked Lists. Which some say that I should not care about deallocating at all. but still worries me.