Dsasxp 07
Dsasxp 07
7
Implement Circular Linked List ADT
Date of Performance:
Date of Submission:
Experiment No. 7: Circular Linked List Operations
Objective: Circular Linked Lists can be used to manage the computing resources of the
computer. Data structures such as stacks and queues are implemented with the help of the
circular linked lists
Theory :
In a circular Singly linked list, the last node of the list contains a pointer to the first node of the
list. We can have circular singly linked list as well as circular doubly linked list.
We traverse a circular singly linked list until we reach the same node where we started. The
circular singly liked list has no beginning and no ending. There is no null value present in the
next part of any of the nodes.
Algorithm
Algorithm :
o Step 1: IF PTR = NULL
Write OVERFLOW
Go to Step 11
[END OF IF]
[END OF LOOP]
#include <stdio.h>
#include <stdlib.h>
// Node structure
struct Node {
int data;
struct Node* next;
};
// Insertion
insertAtEnd(&head, 10);
insertAtEnd(&head, 20);
insertAtBeginning(&head, 5);
insertAtPosition(&head, 15, 2);
// Traversal
printf("Circular Linked List: ");
traverse(head);
// Deletion
deleteFromEnd(&head);
deleteAtPosition(&head, 1);
// Searching
int key = 10;
if (search(head, key)) {
printf("Element %d is found in the linked list.\n",
key);
}
else {
printf(
"Element %d is not found in the linked list.\n",
key);
}
return 0;
}
OUTPUT: