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
Void addfront()
{
struct node *t=start;
struct node *n=(struct
node*)malloc(sizeof(struct
node));
printf(“nenter the
information”);
scanf(“%d”,&n->info);
• 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.
Algorithm Program
if(start==NULL)
{
start=n;
start->next=start;
}
else
{
n->next=start;
while(t->next!=start)
t=t->next;
t->next=n;
start=n;
}
• 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.
Insert at last
Algorithm Program
Void addlast()
{
struct node *t=start;
• 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.
struct node *n=(struct
node*)malloc(sizeof(struct
node));
printf(“nenter the
information”);
scanf(“%d”,&n->info);
Algorithm Program
if(start==NULL)
{
start=n;
start->next=start;
}
else
{
n->next=start;
while(t!=NULL)
t=t->next;
t->next=n;
}
• Repeat step(a)
while(t!=NULL)
▫ (a) set t:=t->next.
• [end of loop]
• Set t->next=n.
[end if]
• Stop.
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
start=start->next;
free(t->next);
t->next=start;
}
• set start:=start-
>next
• Declare free(t-
>next).
• Set t->next:=start.
• [end of if]
• stop
}
Delete from last
Algorithm Program
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;
}
}
• 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
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

Similar to circularlinklist-190205164051.pptx

ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfKamranAli649587
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
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 KristinaBorooah
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in CJabs6
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdfSonaPathak5
 
Advance data structure
Advance data structureAdvance data structure
Advance data structureashok kumar
 
2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions2 Important Data Structure Interview Questions
2 Important Data Structure Interview QuestionsGeekster
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxAhmedEldesoky24
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxskilljiolms
 
Remove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in PythonRemove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in PythonKal Bartal
 

Similar to circularlinklist-190205164051.pptx (20)

Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
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 in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.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
 
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
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdf
 
Advance data structure
Advance data structureAdvance data structure
Advance data structure
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
Linked list
Linked listLinked list
Linked list
 
ds bridge.pptx
ds bridge.pptxds bridge.pptx
ds bridge.pptx
 
Linkedlists
LinkedlistsLinkedlists
Linkedlists
 
2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptx
 
Remove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in PythonRemove Duplicates in an Unsorted Linked List in Python
Remove Duplicates in an Unsorted Linked List in Python
 
Linked list
Linked listLinked list
Linked list
 

More from MeghaKulkarni27

Note for Java Programming////////////////
Note for Java Programming////////////////Note for Java Programming////////////////
Note for Java Programming////////////////MeghaKulkarni27
 
Different string operations....................
Different string operations....................Different string operations....................
Different string operations....................MeghaKulkarni27
 
virtual reality...............................
virtual reality...............................virtual reality...............................
virtual reality...............................MeghaKulkarni27
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxMeghaKulkarni27
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxMeghaKulkarni27
 

More from MeghaKulkarni27 (11)

Note for Java Programming////////////////
Note for Java Programming////////////////Note for Java Programming////////////////
Note for Java Programming////////////////
 
Different string operations....................
Different string operations....................Different string operations....................
Different string operations....................
 
virtual reality...............................
virtual reality...............................virtual reality...............................
virtual reality...............................
 
positive.pptx
positive.pptxpositive.pptx
positive.pptx
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
 

Recently uploaded

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

circularlinklist-190205164051.pptx

  • 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 Void addfront() { struct node *t=start; struct node *n=(struct node*)malloc(sizeof(struct node)); printf(“nenter the information”); scanf(“%d”,&n->info); • 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.
  • 14. Algorithm Program if(start==NULL) { start=n; start->next=start; } else { n->next=start; while(t->next!=start) t=t->next; t->next=n; start=n; } • 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.
  • 16. Algorithm Program Void addlast() { struct node *t=start; • 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. struct node *n=(struct node*)malloc(sizeof(struct node)); printf(“nenter the information”); scanf(“%d”,&n->info);
  • 17. Algorithm Program if(start==NULL) { start=n; start->next=start; } else { n->next=start; while(t!=NULL) t=t->next; t->next=n; } • Repeat step(a) while(t!=NULL) ▫ (a) set t:=t->next. • [end of loop] • Set t->next=n. [end if] • Stop.
  • 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 start=start->next; free(t->next); t->next=start; } • set start:=start- >next • Declare free(t- >next). • Set t->next:=start. • [end of if] • stop }
  • 23. Algorithm Program 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; } } • 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
  • 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); } }