Doubly Circular Linked List in Java

In previous post, we saw the implementation of Singly Circular Linked List. Now in this post, we will understand the Doubly Circular Linked List and implement it JAVA. Doubly circular linked list is quite similar to singly circular linked list but only difference is, in case of doubly circular linked list, traversal of nodes is possible in both backward and forward directions. To implement the doubly circular linked list, we will use Doubly Node to support backward and forward traversing.

Now, We will see the implementation of add and delete operations of doubly circular linked list in java. It’s recommended to refer the add and delete operations of doubly linked list before going for doubly circular linked list. The only difference between doubly linked list and doubly circular linked list is, in case of doubly linked list, next pointer of last node will be always NULL but in case of doubly circular linked list, next pointer of last node will be start node to form loop.

DoublyNode.java

Below is the DoublyCircularLinkedList class having add and delete operations. Also, class is implementing the iterable  interface to have iterator functionality. Since, doubly circular linked list provides the facility to traverse in backward direction also, we need to implement the ReverseIterator. Below code doesn’t have the Reverse Iterator implementation. Try yourself. For your reference, see the post “Iterator for Doubly Linked List”

DoublyCircularLinkedList.java

 

Player.java

DoublyCircularLinkedListTest.java

 

Output:

 

Player [playerId=1, playerName=Jhon]
Player [playerId=2, playerName=Tom]
Player [playerId=3, playerName=Jerry]
Player [playerId=4, playerName=Smith]
Player [playerId=1, playerName=Jhon]
Player [playerId=2, playerName=Tom]
Player [playerId=3, playerName=Jerry]
Player [playerId=4, playerName=Smith]
Player [playerId=1, playerName=Jhon]
Player [playerId=2, playerName=Tom]
Player [playerId=3, playerName=Jerry]
Player [playerId=4, playerName=Smith]
Player [playerId=1, playerName=Jhon]
Player [playerId=2, playerName=Tom]
Player [playerId=3, playerName=Jerry]
Player [playerId=4, playerName=Smith]
Player [playerId=1, playerName=Jhon]
Player [playerId=2, playerName=Tom]
Player [playerId=3, playerName=Jerry]
Player [playerId=4, playerName=Smith]

 

Hope you liked this post. Please leave your comments/suggestions.

 

You may like:

Singly Circular Linked List

Singly Linked List

Doubly Linked List

 

Top