Tutorial Playlist
Data Structure Tutorial
OverviewArrays in Data Structures: A Guide With Examples
Lesson - 1All You Need to Know About Two-Dimensional Arrays
Lesson - 2All You Need to Know About a Linked List in a Data Structure
Lesson - 3The Complete Guide to Implement a Singly Linked List
Lesson - 4The Ultimate Guide to Implement a Doubly Linked List
Lesson - 5The Fundamentals for Understanding Circular Linked List
Lesson - 6The Ultimate Guide To Understand The Differences Between Stack And Queue
Lesson - 7Implementing Stacks in Data Structures
Lesson - 8Your One-Stop Solution for Stack Implementation Using Array
Lesson - 9Your One-Stop Solution for Queue Implementation Using Array
Lesson - 10Your One-Stop Solution to Learn Depth-First Search(DFS) Algorithm From Scratch
Lesson - 11Your One-Stop Solution for Stack Implementation Using Linked-List
Lesson - 12The Definitive Guide to Understand Stack vs Heap Memory Allocation
Lesson - 13All You Need to Know About Linear Search Algorithm
Lesson - 14All You Need to Know About Breadth-First Search Algorithm
Lesson - 15A One-Stop Solution for Using Binary Search Trees in Data Structure
Lesson - 16The Best Tutorial to Understand Trees in Data Structure
Lesson - 17A Complete Guide to Implement Binary Tree in Data Structure
Lesson - 18A Holistic Look at Using AVL Trees in Data Structures
Lesson - 19All You Need to Know About Tree Traversal in Data Structure
Lesson - 20The Best Guide Youll Ever Need to Understand B-Tree in Data Structure
Lesson - 21The Best Guide You'll Ever Need to Understand Spanning Tree in Data Structure
Lesson - 22The Best and Easiest Way to Understand an Algorithm
Lesson - 23Your One-Stop Solution to Understand Shell Sort Algorithm
Lesson - 24Your One-Stop Solution to Quick Sort Algorithm
Lesson - 25The Most Useful Guide to Learn Selection Sort Algorithm
Lesson - 26Everything You Need to Know About Radix Sort Algorithm
Lesson - 27Everything You Need to Know About the Counting Sort Algorithm
Lesson - 28Everything You Need to Know About the Merge Sort Algorithm
Lesson - 29Insertion Sort Algorithm: One-Stop Solution That Will Help You Understand Insertion Sort
Lesson - 30Everything You Need to Know About the Bubble Sort Algorithm
Lesson - 31The Best Guide Youll Ever Need to Understand Bucket Sort Algorithm
Lesson - 32Your One-Stop Solution to Understand Recursive Algorithm in Programming
Lesson - 33The Definitive Guide to Understanding Greedy Algorithm
Lesson - 34Your One-Stop Solution to Understand Backtracking Algorithm
Lesson - 35The Fundamentals of the Bellman-Ford Algorithm
Lesson - 36Your One-Stop Solution for Graphs in Data Structures
Lesson - 37The Best Guide to Understand and Implement Solutions for Tower of Hanoi Puzzle
Lesson - 38A Simplified and Complete Guide to Learn Space and Time Complexity
Lesson - 39All You Need to Know About the Knapsack Problem : Your Complete Guide
Lesson - 40The Fibonacci Series: Mathematical and Programming Interpretation
Lesson - 41The Holistic Look at Longest Common Subsequence Problem
Lesson - 42The Best Article to Understand What Is Dynamic Programming
Lesson - 43A Guide to Implement Longest Increasing Subsequence Using Dynamic Programming
Lesson - 44A Holistic Guide to Learn Stop Solution Using Dynamic Programming
Lesson - 45One Stop Solution to All the Dynamic Programming Problems
Lesson - 46Understanding the Fundamentals of Binomial Distribution
Lesson - 47Heres All You Need to Know About Minimum Spanning Tree in Data Structures
Lesson - 48Understanding the Difference Between Array and Linked List
Lesson - 49The Best Article Out There to Understand the B+ Tree in Data Structure
Lesson - 50A Comprehensive Look at Queue in Data Structure
Lesson - 51Your One-Stop Solution to Understand Coin Change Problem
Lesson - 52The Best Way to Understand the Matrix Chain Multiplication Problem
Lesson - 53Your One-Stop Solution to Learn Floyd-Warshall Algorithm for Using Dynamic Programming
Lesson - 54Circular Linked List: Understanding The Fundamentals
Lesson 6 of 54By Simplilearn
Last updated on Sep 18, 20211168- Tutorial Playlist
Data Structure Tutorial
OverviewArrays in Data Structures: A Guide With Examples
Lesson - 1All You Need to Know About Two-Dimensional Arrays
Lesson - 2All You Need to Know About a Linked List in a Data Structure
Lesson - 3The Complete Guide to Implement a Singly Linked List
Lesson - 4The Ultimate Guide to Implement a Doubly Linked List
Lesson - 5The Fundamentals for Understanding Circular Linked List
Lesson - 6The Ultimate Guide To Understand The Differences Between Stack And Queue
Lesson - 7Implementing Stacks in Data Structures
Lesson - 8Your One-Stop Solution for Stack Implementation Using Array
Lesson - 9Your One-Stop Solution for Queue Implementation Using Array
Lesson - 10Your One-Stop Solution to Learn Depth-First Search(DFS) Algorithm From Scratch
Lesson - 11Your One-Stop Solution for Stack Implementation Using Linked-List
Lesson - 12The Definitive Guide to Understand Stack vs Heap Memory Allocation
Lesson - 13All You Need to Know About Linear Search Algorithm
Lesson - 14All You Need to Know About Breadth-First Search Algorithm
Lesson - 15A One-Stop Solution for Using Binary Search Trees in Data Structure
Lesson - 16The Best Tutorial to Understand Trees in Data Structure
Lesson - 17A Complete Guide to Implement Binary Tree in Data Structure
Lesson - 18A Holistic Look at Using AVL Trees in Data Structures
Lesson - 19All You Need to Know About Tree Traversal in Data Structure
Lesson - 20The Best Guide Youll Ever Need to Understand B-Tree in Data Structure
Lesson - 21The Best Guide You'll Ever Need to Understand Spanning Tree in Data Structure
Lesson - 22The Best and Easiest Way to Understand an Algorithm
Lesson - 23Your One-Stop Solution to Understand Shell Sort Algorithm
Lesson - 24Your One-Stop Solution to Quick Sort Algorithm
Lesson - 25The Most Useful Guide to Learn Selection Sort Algorithm
Lesson - 26Everything You Need to Know About Radix Sort Algorithm
Lesson - 27Everything You Need to Know About the Counting Sort Algorithm
Lesson - 28Everything You Need to Know About the Merge Sort Algorithm
Lesson - 29Insertion Sort Algorithm: One-Stop Solution That Will Help You Understand Insertion Sort
Lesson - 30Everything You Need to Know About the Bubble Sort Algorithm
Lesson - 31The Best Guide Youll Ever Need to Understand Bucket Sort Algorithm
Lesson - 32Your One-Stop Solution to Understand Recursive Algorithm in Programming
Lesson - 33The Definitive Guide to Understanding Greedy Algorithm
Lesson - 34Your One-Stop Solution to Understand Backtracking Algorithm
Lesson - 35The Fundamentals of the Bellman-Ford Algorithm
Lesson - 36Your One-Stop Solution for Graphs in Data Structures
Lesson - 37The Best Guide to Understand and Implement Solutions for Tower of Hanoi Puzzle
Lesson - 38A Simplified and Complete Guide to Learn Space and Time Complexity
Lesson - 39All You Need to Know About the Knapsack Problem : Your Complete Guide
Lesson - 40The Fibonacci Series: Mathematical and Programming Interpretation
Lesson - 41The Holistic Look at Longest Common Subsequence Problem
Lesson - 42The Best Article to Understand What Is Dynamic Programming
Lesson - 43A Guide to Implement Longest Increasing Subsequence Using Dynamic Programming
Lesson - 44A Holistic Guide to Learn Stop Solution Using Dynamic Programming
Lesson - 45One Stop Solution to All the Dynamic Programming Problems
Lesson - 46Understanding the Fundamentals of Binomial Distribution
Lesson - 47Heres All You Need to Know About Minimum Spanning Tree in Data Structures
Lesson - 48Understanding the Difference Between Array and Linked List
Lesson - 49The Best Article Out There to Understand the B+ Tree in Data Structure
Lesson - 50A Comprehensive Look at Queue in Data Structure
Lesson - 51Your One-Stop Solution to Understand Coin Change Problem
Lesson - 52The Best Way to Understand the Matrix Chain Multiplication Problem
Lesson - 53Your One-Stop Solution to Learn Floyd-Warshall Algorithm for Using Dynamic Programming
Lesson - 54
Table of Contents
View MoreA circular linked list is used to loop your music playlist to implement a circular queue. A circular linked list is a unidirectional linked list; i.e., you can traverse it from head to tail. Unlike other linked lists, its tail points back at the head node. This tutorial will help you understand the fundamental technicalities of circular linked lists with all the necessary details and practical examples.
How to Implement a Circular Linked List?
You can create nodes of circular-linked lists using classes or structures. These nodes are then linked with each other using the next pointer.
Code:
//A c++ program to implement linked list
#include <bits/stdc++.h>
using namespace std;
//A class to create a node
class Node
{
public:
int data;
Node *next;
};
// a function to insert a node at the beginning
void push(Node **head, int data)
{
Node *newnode = new Node();
Node *temp = *head;
newnode->data = data;
newnode->next = *head;
//If linked list is not NULL then
//set the next of last node as newnode
if (*head != NULL)
{
while (temp->next != *head)
temp = temp->next;
temp->next = newnode;
}
else
newnode->next = newnode;
*head = newnode;//change head
}
//A function to print the linked list
void printList(Node *head)
{
Node *temp = head;
if (head != NULL)
{
do
{
cout << temp->data << " ";
temp = temp->next;
}
while (temp != head);
}
}
int main()
{
//we will start with empty list
Node *head = NULL;
// insert 12
push(&head, 12);//12->12
//insert 56
push(&head, 56);//56->12->56
//insert 2
push(&head, 2);//2->56->12->2
//Insert 11
push(&head, 11);//11->2->56->12->11
cout << "Created Linked List: \n ";
printList(head);
return 0;
}
Full Stack Web Developer Course
To become an expert in MEAN StackView CourseWhat Operations Can You Perform on a Circular Linked List?
You can perform two types of operations on this kind of linked list:
- Insertion
- Deletion
How to Insert a Node in a Circular Linked List?
To insert a node, you need to change the previous node's next (if any) to the new node and the new node next to the previous node's next. You can insert a new node in three different locations.
- At the beginning of the list
- At the end of the list
- After a given node
Code:
//A c++ program to perform insertion.
#include<bits/stdc++.h>
using namespace std;
//A structure to create nodes
struct Node
{
int data;
struct Node *next;
};
//A function to insert in the empty list
struct Node *addToEmpty(struct Node *last, int data)
{
// Check if list is empty
if (last != NULL)
return last;
// Creating a node dynamically.
struct Node *temp=(struct Node*)malloc(sizeof(struct Node));
// Assigning the data.
temp -> data = data;
last = temp;
// Creating the link.
last -> next = last;
return last;
}
//A function to insert at the beginning
struct Node *addBegin(struct Node *last, int data)
{
if (last == NULL)
return addToEmpty(last, data);
struct Node *temp=(struct Node *)malloc(sizeof(struct Node));
temp -> data = data;
temp -> next = last -> next;
last -> next = temp;
return last;
}
//A function to insert at the end
struct Node *addEnd(struct Node *last, int data)
{
if (last == NULL)
return addToEmpty(last, data);
struct Node *temp =
(struct Node *)malloc(sizeof(struct Node));
temp -> data = data;
temp -> next = last -> next;
last -> next = temp;
last = temp;
return last;
}
//A function to insert after the given node
struct Node *addAfter(struct Node *last, int data, int item)
{
if (last == NULL)
return NULL;
struct Node *temp, *p;
p = last -> next;
do
{
if (p ->data == item)
{
temp = (struct Node *)malloc(sizeof(struct Node));
temp -> data = data;
temp -> next = p -> next;
p -> next = temp;
if (p == last)
last = temp;
return last;
}
p = p -> next;
} while(p != last -> next);
cout << item << " not present in the list." << endl;
return last;
}
//A function to traverse and print the list
void traverse(struct Node *last)
{
struct Node *p;
// If the list is empty, return.
if (last == NULL)
{
cout << "List is empty." << endl;
return;
}
// Points to first node
p = last -> next;
// Traversing the list.
do
{
cout << p -> data << " ";
p = p -> next;
}
while(p != last->next);
}
int main()
{
//start with empty list
struct Node *head = NULL;
//insert 6 in empty list
head = addToEmpty(head, 6);//6->6
//insert 4 at the beginning
head = addBegin(head, 4);//4->6->4
//insert 2 at the beginning
head = addBegin(head, 2);//2->4->6->2
//insert 8 at the end
head = addEnd(head, 8);//2->4->6->8->2
//insert 12 at the end
head = addEnd(head, 12);//2->4->6->8->12->2
//insert 10 after 8
head = addAfter(head, 10, 8);//2->4->6->8->10->12->2
traverse(head);
return 0;
}
Add Another Star to Your Performance Evaluation
Learn from industry experts for FREEStart LearningHow to Remove a Node From a Circular Linked List?
You need to change the previous node's next to the deleted node's next to delete a node. You can delete a node from three different positions.
- From the beginning of the list
- From the end of the list
- After a given node
Code:
//A C++ program to delete a given key
#include <bits/stdc++.h>
using namespace std;
// A class to create node
class Node {
public:
int data;
Node* next;
};
//A function to insert at the beginning
void push(Node** head, int data)
{
// Creating a newnode and make its next as head
Node* newnode = new Node();
newnode->data = data;
newnode->next = *head;
//If linked list is not empty
if (*head!= NULL)
{
// Find the node before head and update
// next to it.
Node* temp = *head;
while (temp->next != *head)
temp = temp->next;
temp->next = newnode;
}
else
newnode->next = newnode;
*head = newnode;
}
//A function to print the list
void printList(Node* head)
{
Node* temp = head;
if (head != NULL) {
do {
cout << temp->data << " ";
temp = temp->next;
} while (temp != head);
}
cout << endl;
}
//A Function to delete a given node
void deleteNode(Node** headref, int key)
{
// If linked list is empty
if (*headref == NULL)
return;
// If the list has single node
if((*headref)->data==key && (*headref)->next==*headref)
{
free(*headref);
*headref=NULL;
return;
}
Node *last=*headref,*d;
// If the key is headref itself
if((*headref)->data==key)
{
// Find the last node of the list
while(last->next!=*headref)
last=last->next;
// Point last node to the next of headref i.e.
// the second node of the list
last->next=(*headref)->next;
free(*headref);
*headref=last->next;
}
//if key not found or end of the list not reached
while(last->next!=*headref && last->next->data!=key)
{
last=last->next;
}
// If node to be deleted was found
if(last->next->data==key)
{
d=last->next;
last->next=d->next;
free(d);
}
else
cout<<"no such key found";
}
/* Driver code */
int main()
{
// we will start list empty
Node* head = NULL;
//Created linked list will be 2->5->7->8->10
push(&head, 2);
push(&head, 5);
push(&head, 7);
push(&head, 8);
push(&head, 10);
cout << "List Before Deletion: ";
printList(head);
deleteNode(&head, 7);//delete 7
cout << "List After Deletion: ";
printList(head);
return 0;
}
What Are the Benefits of a Circular Linked List?
- You can traverse to any node from any node.
- It is faster to traverse from the last node to the first node.
- The circular linked list is beneficial in applications that require looping.
- You can implement complex data structures like circular queues.
What Are the Limitations of a Circular Linked List?
- It is hard to reverse traverse a circular linked list.
- While traversing, if not careful, you can end up in an infinite loop.
- Similar to singly linked lists and doubly linked lists, you can't directly access any element of the linked lists.
Advance your career as a MEAN stack developer with theFull Stack Web Developer - MEAN Stack Master's Program. Enroll now!
Next Steps
"Stacks in data structure" will be your next stop. Stacks are nodes that are piled on one another. You can perform operations only on the top node. Stacks can be used to backtrack to the previous installation or to solve complex problems like N-Queens.
If you are perhaps looking to build a career in software development, explore Simplilearns Software Development Courses that will give you the work-ready software development training you need to succeed today.
If you have any questions about this article, please feel free to leave them in the comment section below. Our expert team is available 24/7 to answer all your queries for you at the earliest.
Happy learning!
About the Author
Simplilearn is one of the worlds leading providers of online training for Digital Marketing, Cloud Computing, Project Management, Data Science, IT, Software Development, and many other emerging technologies.
Recommended Resources
- Video Tutorial
All You Need to Know About a Linked List in a Data Structure
- Ebook
IT Skills Training Trends: 2020 and 2021
- Article
Linked List in Java
- Video Tutorial
The Ultimate Guide to Implement a Doubly Linked List
- Video Tutorial
The Complete Guide to Implement a Singly Linked List
- Ebook
Azure Functions
© 2009 -2022- Simplilearn Solutions
Follow us!
Refer and EarnCompany
About usCareers In the media Alumni speakContact usWork with us
Become an instructorBlog as guestDiscover
SkillupResourcesRSS feedSimplilearn Coupons and Discount OffersCity SitemapFor Businesses
Corporate trainingPartnersDigital TransformationLearn On the Go!
Get the Android AppGet the iOS AppTrending Post Graduate Programs
Project Management Certification Course | Cyber Security Certification Course | Data Science Bootcamp Program | Data Analytics Bootcamp Program | Business Analysis Certification Course | Digital Marketing Certification Program | Lean Six Sigma Certification Course | DevOps Certification Course | Cloud Computing Certification Course | Data Engineering Course | AI and Machine Learning Course | Full Stack Web Development CourseTrending Master Programs
PMP Plus Certification Training Course | Big Data Engineer Course | Data Science Certification Course | Data Analyst Certification Course | Artificial Intelligence Course | Cloud Architect Certification Training Course | DevOps Engineer Certification Training Course | Advanced Digital Marketing Course | Cyber Security Expert Course | MEAN Stack Developer CourseTrending Courses
PMP Certification Training Course | Big Data Hadoop Certification Training Course | Data Science with Python Certification Course | Machine Learning Certification Course | AWS Solutions Architect Certification Training Course | CISSP Certification Training | Certified ScrumMaster (CSM) Certification Training | ITIL 4 Foundation Certification Training Course | Java Certification Course | Python Certification Training CourseTrending Resources
Python Tutorial | JavaScript Tutorial | Java Tutorial | Angular Tutorial | Node.js Tutorial | Docker Tutorial | Git Tutorial | Kubernetes Tutorial | Power BI Tutorial | CSS Tutorial- Terms of Use
- Privacy Policy
- Refund Policy
- Reschedule Policy
- © 2009-2022 - Simplilearn Solutions. All Rights Reserved. The certification names are the trademarks of their respective owners.
- Disclaimer
- PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.