Deletion of entire Double linked list

Doubly Linked List in java - Java2Blog
Simply,
head = null;
tail = null;

will not work in case of Double Linked List. The reason for this is that, we have a previous node too, which will point to the previous node even if we make head=tail=null.

So, the solution for this is that, we loop through the linked list and make all the prev=null (for each node.). Now, after this if we do head=tail=null, the entire linked list is deleted.

Note : The nodes in any linked list is deleted one by one and not vanished all at once by garbage collection.

Comments

Popular posts from this blog

Quick Sort

Graph Traversal Code - BFS on Graph represented using Adjacency Matrix

Disjoint Set - Implemented Using Arrays