Professional Documents
Culture Documents
EC-233 Data Structures and Algorithms: Lab Report#05
EC-233 Data Structures and Algorithms: Lab Report#05
LAB REPORT#05
Submitted by:
Mahnoor inam
18-ce-009
Lab.Instructor
Tauqeer Anjum
Experiment # 05
Objectives:
The objective of this lab is to understand the various operations on Circular linked list in C++.
• Insertion
• Deletion
Software Tools:
Theory:
A circular linked list is a variation of the linked list. It is a linked list whose nodes are connected
in such a way that it forms a circle.In the circular linked list, the next pointer of the last node is
not set to null but it contains the address of the first node thus forming a circle.
• Games that are played with multiple players can also be represented using a circular
linked list in which each player is a node that is given a chance to play.
• We can use a circular linked list to represent a circular queue. We can remove the two
pointers front and rear that is used for the queue. Instead, we can use only one pointer.
Task
Perform the following operations in circular doubly linked list
Insertion at the Start
Insertion at the Middle
Insertion at the End
Deletion at the start
Deletion at the Middle
Deletion at the end
Display linked list
Search item in the list
Code:
#include<iostream>
struct node
int data;
node *next;
node *prev;
};
class list
private:
node *head, *tail;
public:
list();
head = NULL;
tail = NULL;
temp->data = value;
if(head == NULL)
head = temp;
tail = temp;
temp = NULL;
else
tail->next= temp;
temp->prev=tail;
tail = temp;
tail->next=head;
head->prev+tail;
}
void display()
current = head;
while(current->next !=tail)
cout<<current->data"t";
current = current->prev;
temp->data = value;
temp-> = head;
heas->prev= temp;
head=temp;
tail->next=head;
head->prev->tail;
for(int i=1;i<pos;i++)
pre = cur;
cur = cur->next;
temp->data = value;
pre->next = temp;
temp->prev=pre;
temp->next=cur;
cur->prev=temp;
void deletestart()
temp = head;
head = head->next;
temp->next=NULL;
temp->prev=NULL;
delete temp;
head->prev=tail;
tail->next=head;
void deleteend()
{
node *current = new node;
current=head;
while(current->next!=tail)
current=current->next;
tail->next=NULL;
tail->prev=NULL;
delete tail;
current->next=head;
head->prev=current;
tail=current;
current = head;
for(int i=1,i<pos;i++)
previous = current;
current = current->next;
previous->next = current->next;
current->next->prev=previous;
current->next-NULL;
current->prev=NULL;
delete current;
void searchitem(int B)
current = head;
while(current->next !=rail)
if(current->data==B)
index++;
current = current->next;
~list()
nodeptr = head;
while (nodeptr !=NULL)
nextnode = nodeptr->next;
delete nodeptr;
nodeptr = nextnode;
};
int main()
list obj;
obj.insertedend(1);
obj.insertedend(2);
obj.insertedend(3);
obj.insertedend(4);
obj.insertedend(5);
obj.display();
obj.insertedstart(7);
obj.insertedstart(8);
obj.display();
obj.display();
obj.deletestart();
obj.display();
obj.deleteend();
obj.display();
obj.deletepos(12);
obj.display();
cout<<"forward display:\n";
obj.display();
cout<<endl;
cout<<"backward display:\n";
obj.displayrev();
cout<<endl;
int n;
cin>>n;
obj-searchitem(n);
return 0;
Conclusion:
In this lab I learned about the circular linklist and its implementation.
END