SlideShare a Scribd company logo
1 of 26
Circular linked
list
Let’s begin..
Content-:
• Circular linked list
• Difference b/w linear linked list and circular
linked list
• Types of circular linked list
• Advantages
• Disadvantages
• Operations based on both the types
Structure of linked list:
What is circular linked list?
• Circular linked list is a variation of linked list in
which the first elements points to the next
element and the last element points to the first
element.
• Both singly and doubly linked list can be made
into a circular linked list.
• Circular linked list can be used to help traverse
the same list again and again if needed.
Fun fact:
If you are worried about its implementation, then stop
doing that because instead of placing NULL at the last
node’s address field you are placing the address of very
first node!
Circular linked list vs. Linear linked list
• A circularly linked list may be a natural option to represent arrays
that are naturally circular, e.g. the corners of a polygon, a pool
of buffers that are used and released in FIFO order, or a set of
processes that should be time-shared. In these applications, a pointer
to any node serves as a handle to the whole list.
• With a circular list, a pointer to the last node gives easy access also to
the first node, by following one link. Thus, in applications that
require access to both ends of the list, a circular structure allows one
to handle the structure by a single pointer, instead of two.
• The simplest representation for an empty circular list (when such a
thing makes sense) is a null pointer, indicating that the list has no
nodes. Without this choice, many algorithms have to test for this
special case, and handle it separately. By contrast, the use of null to
denote an empty linear list is more natural and often creates fewer
special cases.
Types of circular linked list:
1. Singly: The last node points to the first node and there is only
link between the nodes of linked list.
2. Doubly: The last node points to the first node and there are two
links between the nodes of linked list.
Advantages of Circular linked lists:
1. Any node can be a starting point. We can traverse the whole
list by starting from any point. We just need to stop when
the first visited node is visited again.
2. 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.
3. Circular Doubly Linked Lists are used for implementation
of advanced data structures like Fibonacci Heap.
Disadvantages of Circular linked list
1. Depending on the implementation, inserting at
start of list would require doing a search for
last node which could be expensive.
2. Finding end of the list and loop control is
harder ( no NULL’s to mark the beginning and
end).
Operations on singly circular
linked list
• Insertion
• Deletion
• Display
Insertion :
• Insertion can be of three types.
▫ Insert at first
▫ Insert at last
▫ Insert after constant
• Note: insertion after constant in circular and
linear linked list is exact same .
Insertion at first
Algorithm Program
• Start.
• Declare struct node *t.
• Set t:=start.
• Create a new node n
by malloc function and
enter the information
in info part.
• Check if start=NULL
set start=n
set start->next=start.
else
• Set n->next=start.
Void addfront()
{
struct node *t=start;
struct node *n=(struct
node*)malloc(sizeof(struct
node));
printf(“nenter the
information”);
scanf(“%d”,&n->info);
Algorithm Program
• Repeat step(a)
while(t->next!=start)
▫ (a) set t:=t->next.
• [end of loop]
• Set t->next=n.
• Set start=n. [end if]
• Stop.
if(start==NULL)
{
start=n;
start->next=start;
}
else
{
n->next=start;
while(t->next!=start)
t=t->next;
t->next=n;
start=n;
}
Insert at last
Algorithm Program
• Start.
• Declare struct node *t.
• Set t:=start.
• Create a new node n
by malloc function and
enter the information
in info part.
• Check if start=NULL
then,
set start:=n.
set start->next:=start.
Otherwise
• Set n->next:=start.
Void addlast()
{
struct node *t=start;
struct node *n=(struct
node*)malloc(sizeof(struct
node));
printf(“nenter the
information”);
scanf(“%d”,&n->info);
Algorithm Program
• Repeat step(a)
while(t!=NULL)
▫ (a) set t:=t->next.
• [end of loop]
• Set t->next=n.
[end if]
• Stop.
if(start==NULL)
{
start=n;
start->next=start;
}
else
{
n->next=start;
while(t!=NULL)
t=t->next;
t->next=n;
}
Deletion :
• Deletion can be of three types.
▫ Delete from front
▫ Delete from last
▫ Deletion from mid
• Note: deletion from mid in circular and linear
linked list is exact same .
Delete from front
Algorithm Program
• start.
• Check if (start=NULL)
then,
print “empty list”
• Check if
(start->next=start)
then,
declare free (t)
set start:=NULL
otherwise
• Repeat step(a)
while(t->next!=start)
▫ (a) set t:=t->next
• [end of loop]
Void delfront()
{
struct node *t=start;
if (start==NULL)
printf (“nempty list”);
else if (start->next==start)
{
free (t);
start=NULL;
}
else
{
while(t->next!=start)
t=t->next;
Algorithm Program
• set start:=start-
>next
• Declare free(t-
>next).
• Set t->next:=start.
• [end of if]
• stop
start=start->next;
free(t->next);
t->next=start;
}
}
Delete from last
Algorithm Program
• start.
• Check if (start=NULL) then,
print “empty list”
• Check if (start->next=start)
then,
declare free (t)
set start:=NULL
otherwise
• Repeat step(a)
while(t->next->next!=start)
▫ (a) set t:=t->next
• [end of loop]
• Declare free(t->next).
• Set t->next:=start.
• [end if]
• stop
Void dellast()
{
struct node *t=start;
if (start==NULL)
printf(“nempty list”);
else if (start->next==start)
{
free (t);
start=NULL ;
}
else
{
while(t->next->next!=start)
t=t->next;
free(t->next);
t->next=start;
}
}
Display
Algorithm Program
• start.
• Set struct node
*t:=start.
• Check if(start=NULL)
then, print “empty list”
otherwise
• Repeat step a and b
while(t->next!=start)
▫ (a) print t->info
▫ (b) set t:=t->next
• [end of loop]
• Print t->info [end if]
• stop
Void display()
{
struct node *t=start;
if(start=NULL)
printf (“nempty list”);
else
{
while(t->next!=start)
{
printf(“%d”, t->info);
t=t->next;
}
printf(“%d”, t->info);
}
}
Thank you

More Related Content

What's hot (20)

Arrays
ArraysArrays
Arrays
 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
single linked list
single linked listsingle linked list
single linked list
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Graph representation
Graph representationGraph representation
Graph representation
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Linked list
Linked listLinked list
Linked list
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Python set
Python setPython set
Python set
 
Linked list
Linked listLinked list
Linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 

Similar to Circular link list.ppt

Similar to Circular link list.ppt (20)

circularlinklist-190205164051.pptx
circularlinklist-190205164051.pptxcircularlinklist-190205164051.pptx
circularlinklist-190205164051.pptx
 
Data Structures 3
Data Structures 3Data Structures 3
Data Structures 3
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
 
Linked List
Linked ListLinked List
Linked List
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocation
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdf
 
Linked list
Linked listLinked list
Linked list
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Linked list
Linked listLinked list
Linked list
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 

Circular link list.ppt

  • 2. Content-: • Circular linked list • Difference b/w linear linked list and circular linked list • Types of circular linked list • Advantages • Disadvantages • Operations based on both the types
  • 4. What is circular linked list? • Circular linked list is a variation of linked list in which the first elements points to the next element and the last element points to the first element. • Both singly and doubly linked list can be made into a circular linked list. • Circular linked list can be used to help traverse the same list again and again if needed.
  • 5. Fun fact: If you are worried about its implementation, then stop doing that because instead of placing NULL at the last node’s address field you are placing the address of very first node!
  • 6. Circular linked list vs. Linear linked list • A circularly linked list may be a natural option to represent arrays that are naturally circular, e.g. the corners of a polygon, a pool of buffers that are used and released in FIFO order, or a set of processes that should be time-shared. In these applications, a pointer to any node serves as a handle to the whole list. • With a circular list, a pointer to the last node gives easy access also to the first node, by following one link. Thus, in applications that require access to both ends of the list, a circular structure allows one to handle the structure by a single pointer, instead of two. • The simplest representation for an empty circular list (when such a thing makes sense) is a null pointer, indicating that the list has no nodes. Without this choice, many algorithms have to test for this special case, and handle it separately. By contrast, the use of null to denote an empty linear list is more natural and often creates fewer special cases.
  • 7. Types of circular linked list: 1. Singly: The last node points to the first node and there is only link between the nodes of linked list. 2. Doubly: The last node points to the first node and there are two links between the nodes of linked list.
  • 8. Advantages of Circular linked lists: 1. Any node can be a starting point. We can traverse the whole list by starting from any point. We just need to stop when the first visited node is visited again. 2. 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. 3. Circular Doubly Linked Lists are used for implementation of advanced data structures like Fibonacci Heap.
  • 9. Disadvantages of Circular linked list 1. Depending on the implementation, inserting at start of list would require doing a search for last node which could be expensive. 2. Finding end of the list and loop control is harder ( no NULL’s to mark the beginning and end).
  • 10. Operations on singly circular linked list • Insertion • Deletion • Display
  • 11. Insertion : • Insertion can be of three types. ▫ Insert at first ▫ Insert at last ▫ Insert after constant • Note: insertion after constant in circular and linear linked list is exact same .
  • 13. Algorithm Program • Start. • Declare struct node *t. • Set t:=start. • Create a new node n by malloc function and enter the information in info part. • Check if start=NULL set start=n set start->next=start. else • Set n->next=start. Void addfront() { struct node *t=start; struct node *n=(struct node*)malloc(sizeof(struct node)); printf(“nenter the information”); scanf(“%d”,&n->info);
  • 14. Algorithm Program • Repeat step(a) while(t->next!=start) ▫ (a) set t:=t->next. • [end of loop] • Set t->next=n. • Set start=n. [end if] • Stop. if(start==NULL) { start=n; start->next=start; } else { n->next=start; while(t->next!=start) t=t->next; t->next=n; start=n; }
  • 16. Algorithm Program • Start. • Declare struct node *t. • Set t:=start. • Create a new node n by malloc function and enter the information in info part. • Check if start=NULL then, set start:=n. set start->next:=start. Otherwise • Set n->next:=start. Void addlast() { struct node *t=start; struct node *n=(struct node*)malloc(sizeof(struct node)); printf(“nenter the information”); scanf(“%d”,&n->info);
  • 17. Algorithm Program • Repeat step(a) while(t!=NULL) ▫ (a) set t:=t->next. • [end of loop] • Set t->next=n. [end if] • Stop. if(start==NULL) { start=n; start->next=start; } else { n->next=start; while(t!=NULL) t=t->next; t->next=n; }
  • 18. Deletion : • Deletion can be of three types. ▫ Delete from front ▫ Delete from last ▫ Deletion from mid • Note: deletion from mid in circular and linear linked list is exact same .
  • 20. Algorithm Program • start. • Check if (start=NULL) then, print “empty list” • Check if (start->next=start) then, declare free (t) set start:=NULL otherwise • Repeat step(a) while(t->next!=start) ▫ (a) set t:=t->next • [end of loop] Void delfront() { struct node *t=start; if (start==NULL) printf (“nempty list”); else if (start->next==start) { free (t); start=NULL; } else { while(t->next!=start) t=t->next;
  • 21. Algorithm Program • set start:=start- >next • Declare free(t- >next). • Set t->next:=start. • [end of if] • stop start=start->next; free(t->next); t->next=start; } }
  • 23. Algorithm Program • start. • Check if (start=NULL) then, print “empty list” • Check if (start->next=start) then, declare free (t) set start:=NULL otherwise • Repeat step(a) while(t->next->next!=start) ▫ (a) set t:=t->next • [end of loop] • Declare free(t->next). • Set t->next:=start. • [end if] • stop Void dellast() { struct node *t=start; if (start==NULL) printf(“nempty list”); else if (start->next==start) { free (t); start=NULL ; } else { while(t->next->next!=start) t=t->next; free(t->next); t->next=start; } }
  • 25. Algorithm Program • start. • Set struct node *t:=start. • Check if(start=NULL) then, print “empty list” otherwise • Repeat step a and b while(t->next!=start) ▫ (a) print t->info ▫ (b) set t:=t->next • [end of loop] • Print t->info [end if] • stop Void display() { struct node *t=start; if(start=NULL) printf (“nempty list”); else { while(t->next!=start) { printf(“%d”, t->info); t=t->next; } printf(“%d”, t->info); } }