Circular Linked List | Set 1 (Introduction and Applications)We have discussed singly and doubly linked lists in the following posts. Show Introduction to Linked List & Insertion Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at the end. A circular linked list can be a singly circular linked list or doubly circular linked list. Advantages of Circular Linked Lists: 2) Useful for implementation of queue. Unlike this implementation, we don’t need to maintain two pointers for front and rear if we use circular linked list. We can maintain a pointer to the last inserted node and front can always be obtained as next of last. 3) Circular lists are useful in applications to repeatedly go around the list. For example, when multiple applications are running on a PC, it is common for the operating system to put the running applications on a list and then to cycle through them, giving each of them a slice of time to execute, and then making them wait while the CPU is given to another application. It is convenient for the operating system to use a circular list so that when it reaches the end of the list it can cycle around to the front of the list. 4) Circular Doubly Linked Lists are used for implementation of advanced data structures like Fibonacci Heap. Next Posts : Please write comments if you find any bug in above code/algorithm, or find other ways to solve the same problem Circular Linked List | Set 1 (Introduction and Applications)We have discussed singly and doubly linked lists in the following posts. Introduction to Linked List & Insertion Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at the end. A circular linked list can be a singly circular linked list or doubly circular linked list. Advantages of Circular Linked Lists: 2) Useful for implementation of queue. Unlike this implementation, we don’t need to maintain two pointers for front and rear if we use circular linked list. We can maintain a pointer to the last inserted node and front can always be obtained as next of last. 3) Circular lists are useful in applications to repeatedly go around the list. For example, when multiple applications are running on a PC, it is common for the operating system to put the running applications on a list and then to cycle through them, giving each of them a slice of time to execute, and then making them wait while the CPU is given to another application. It is convenient for the operating system to use a circular list so that when it reaches the end of the list it can cycle around to the front of the list. 4) Circular Doubly Linked Lists are used for implementation of advanced data structures like Fibonacci Heap. Next Posts : Please write comments if you find any bug in above code/algorithm, or find other ways to solve the same problem
Article Tags :
Linked List
circular linked list Practice Tags :
Linked List circular linked list Doubly Linked List | Set 1 (Introduction and Insertion)We strongly recommend to refer following post as a prerequisite of this post. Following is representation of a DLL node in C language. C++
C
Java
Python3
C#
Javascript
Following are advantages/disadvantages of doubly linked list over singly linked list. Disadvantages over singly linked list Recommended: Please solve it on “PRACTICE” first, before moving on to the solution. 1) Add a node at the front: (A 5 steps process) Following are the 5 steps to add node at the front. C++
C
Java
Python3
C#
Javascript
Four steps of the above five steps are same as the 4 steps used for inserting at the front in singly linked list. The only extra step is to change previous of head. C++
C
Java
Python3
C#
Javascript
Five of the above steps step process are same as the 5 steps used for inserting after a given node in singly linked list. The two extra steps are needed to change previous pointer of new node and previous pointer of new node’s next node. Following are the 7 steps to add node at the end. C++
C
Java
Python3
C#
Javascript
Six of the above 7 steps are same as the 6 steps used for inserting after a given node in singly linked list. The one extra step is needed to change previous pointer of new node. Steps
Below is the implementation of the above approach: Code block Output: Created DLL is: Traversal in forward Direction 9 1 5 7 6 Traversal in reverse direction 6 7 5 1 9 A complete working program to test above functions. C++
C
Java
Python3
C#
Javascript
Output: Created DLL is: Traversal in forward Direction 1 7 5 8 6 4 Traversal in reverse direction 4 6 8 5 7 1Also see: Delete a node in double Link List
Article Tags :
Data Structures Linked List
doubly linked list Visa Practice Tags :
Visa Data Structures Linked List MCQs on Linked list with answers
Circular Doubly Linked ListCircular doubly linked list is a more complexed type of data structure in which a node contain pointers to its previous node as well as the next node. Circular doubly linked list doesn't contain NULL in any of the node. The last node of the list contains the address of the first node of the list. The first node of the list also contain address of the last node in its previous pointer. A circular doubly linked list is shown in the following figure. Due to the fact that a circular doubly linked list contains three parts in its structure therefore, it demands more space per node and more expensive basic operations. However, a circular doubly linked list provides easy manipulation of the pointers and the searching becomes twice as efficient. |