# Circular Linked Lists

A linked list in which the last node points to the first node is called a circular linked list. Circular linked lists avoid the use of null references in their nodes. Can be useful for certain algorithms like playing video/audio files repeatedly and ALT + TAB in Windows.

Successor of tail node is the head node. In doubly-linked list, predecessor of head node is the tail node. Insertions and deletions into a circular linked list follow the same logic patterns used in a singly linked list except that the last node must always point to the first node. Therefore, when inserting or deleting the last node, in addition to updating the tail pointer, we must also point the link field of the new last node to the first node.

Advantage is that we can start searching from any node of the linked list and get to any other node. No logical head and tail pointers. However, we follow the conventions i.e., first element inserted into the list is given status of head and last element entered is called as a tail.

Some characteristics of Circular Linked list are that the Last node references the first node, every node has a successor, and no node in a circular linked list contains NULL.

**Defining a Circular Linked List:**

#include <iostream> using namespace std; struct Node{ int data; Node* next; }; Node* NodePtr;

**Insert into an empty Circular Linked list**

Node *loc = new Node; loc->data = 10; Tail = loc; Tail->next = Tail;

**Insert to head of a Circular Linked List**

loc->next = Tail->next; Tail->next = loc;

**Insert to end of a Circular Linked List**

loc->next = Tail->next; Tail->next = loc; Tail = loc;

**Delete a node from a single-node Circular Linked List**

Cur = Tail; Tail = NULL; delete Cur;

**Delete the head node from a Circular Linked List**

Cur = Tail -> next; Tail->next = Cur->next delete Cur;

**Delete the end node from a Circular Linked List**

Prev->next = Tail->next; delete Tail; Tail = Prev;

### Example use of Circular Linked list

Ever wonder what to do if the integer size required by your program is greater than 232, 264, 2512, 21024? 4294967296 and greater CANNOT be handled by primitive int data type. What we can do is make use of linked lists. To Add two such long integers, their digits are traversed from right to left. The corresponding digits are added and the possible carry is added to the next digit.

We store the integers from right to left in a list so that the first node contains the least significant digit (rightmost). And the last node contains the most significant digit (leftmost). We keep five digits in each node.

### C++ Program to Implement Circular Linked List

Click here see application of circular linked list in data structure

### Related Posts

- Doubly Linked Lists
- Linked lists in C++
- Queues in C++
- Insertion Sort: A Graphical Explanation
- Binary Trees and Binary Search Trees
- Operations on Binary Search Trees (BST)
- Queue Implementation in C++
- Binary Search Trees and Data Structure
- Selection Sort: A Graphical Explanation
- Implementation of Priority Queue using Heap data structure in C++
- Implementing Stack Data Structure in C++
- Introduction to Tree Data Structure

### 2 Responses to *Circular Linked Lists*

### Leave a Reply Cancel reply

### Popular Posts (last 30 days)

- Attendance Management Sys… 1310 view(s)
- Circular Linked Lists 382 view(s)
- Applications of Stack in … 339 view(s)
- Graph Implementation in C… 257 view(s)
- JAVA Graphical User Inter… 220 view(s)
- GRASP Design Patterns 150 view(s)
- Top 3 open source voice b… 107 view(s)
- C++ Tutorial for Intermed… 106 view(s)
- Linked lists in C++ 89 view(s)
- Advanced Java Tutorial (F… 89 view(s)

### Related Links

### Tags

Android C-Sharp C/C++ language Classes Data structures Design Pattern Eclipse Game Development Graphics Design Books HTML iPhone JAVA JAVA GUI MIPS Assembly Mobile Programming Books Object Oriented PDF PHP Programming Programming Books Programming Languages Books Python RaphaelJS REST Source Code Threads Tutorial Web Development Books

Thanks for the example and source code on a linked list, exactly what I was looking for, very informative!! Check my Coder Forum I have source similar to this, again thank you!

thanks!!!!!!!