SlideShare a Scribd company logo
P a g e |1

Circular List

/* WAP
1. Insert A Node Into Front Of A Circular Linked List.
2. Delete A Node From The Front End.
3. Display. */
#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *next;
};
typedef struct node NODE;
void c_ins_first(NODE**, int);
int c_del_first(NODE**);
void c_display(NODE*);
int main()
{
NODE *first=NULL;
int choice, item;
for(;;)
{
printf("Circular Linked Listn");
printf("1.Insert Frontn");
printf("2.Delete Frontn");
printf("3.Displayn");
printf("4.Exitn");
printf("Enter U R Choicen");
scanf("%d", &choice);
printf("nn");
switch(choice)
{
case 1 : printf("Enter The Item To Insertn");
scanf("%d", &item);
printf("nn");
c_ins_first(&first, item);
break;
case 2 : item=c_del_first(&first);
if(item!='0')
printf("Deleted Element Is %dnn", item);
break;
case 3 : printf("Contents Of Stack Aren");
c_display(first);
break;
default : exit(0);

Ashok R
P a g e |2

}

Circular List

}
}
return 1;

void c_ins_first(NODE **first, int item)
{
NODE *newn, *travel;
newn=(NODE*)malloc(sizeof(NODE));
newn->info=item;
if(*first==NULL)
{
newn->next=newn;
*first=newn;
}
else
{
travel=*first;
while(travel->next!=*first)
travel=travel->next;
newn->next=*first;
travel->next=newn;
*first=newn;
}
}

int c_del_first(NODE **first)
{
int item;
NODE *travel, *temp;
if(*first==NULL)
{
printf("List Is Emptynn");
return('0');
}
temp=*first;
travel=*first;
if(temp->next==*first) /* If There Is Only One Node Delete It */
{
item=temp->info;
*first=NULL;
free(temp);
return item;
}

Ashok R
P a g e |3

}

Circular List

while(travel->next!=*first) /* List Contain More Than One Nodes */
travel=travel->next;
item=temp->info;
*first=temp->next;
travel->next=temp->next; /* OR travel->next=*first */
free(temp);
return item;

void c_display(NODE *first)
{
NODE *travel;
travel=first;
if(first==NULL)
{
printf("List Is Emptynn");
}
else
{
while(travel->next!=first)
{
printf("%dn", travel->info);
travel=travel->next;
}
printf("%dnn", travel->info);
}
}

Ashok R
P a g e |4

Circular List

/* Insert Node Last */
case 4 :

printf("Enter The Item To Insertn");
scanf("%d", &item);
printf("nn");
c_ins_last(&first, item);
break;

void c_ins_last(NODE **first, int item)
{
NODE *newn, *travel;
newn=(NODE*)malloc(sizeof(NODE));
newn->info=item;
if(*first==NULL)
{
newn->next=newn;
*first=newn;
}
else
{
travel=*first;
while(travel->next!=*first)
travel=travel->next;
newn->next=travel->next;
travel->next=newn;
}
}

Ashok R
P a g e |5

Circular List

Delete Last
case 5 : item=c_del_last(&first);
if(item!='0')
printf("Deleted Element Is %dnn", item);
break;
int c_del_last(NODE **first)
{
int item;
NODE *travel, *temp;
if(*first==NULL)
{
printf("List Is Emptynn");
return('0');
}
temp=*first;
travel=*first;
if(temp->next==*first) /* If There Is Only One Node Delete It */
{
item=temp->info;
*first=NULL;
free(temp);
return item;
}
while(travel->next!=*first) /* List Contain More Than One Nodes */
{
temp=travel;
travel=travel->next;
}
item=travel->info;
temp->next=travel->next;
free(travel);
return item;
}

Ashok R
P a g e |6

Circular List

Ashok R

CIRCULAR LIST.
WRITE A PROGRAM TO SEARCH A NODE WITH A VALUE K , IF IT IS NOT FOUND THEN INSERT VALUE AS
LAST NODE.
void c_ins_k(NODE **first, int k)
{
NODE *newn, *travel, *temp;
int flag=0;
newn=(NODE*)malloc(sizeof(NODE));
newn->info=k;
travel=*first;
if(*first==NULL)
{
/* List Is Empty, So Element k Is Inserted As Last Node */
newn->next=newn;
*first=newn;
}
else if(travel->info==k) /* Item Found At 1st Postion */
flag=1;
else
{
temp=*first; /* Initially Pointing To 1st Item In A List */
travel=temp->next; /* Initially Pointing To 2nd Item In A List */
while(travel!=*first && flag==0)
{
if(travel->info==k)
{
flag=1;
break;
}
travel=travel->next;
}
}

}

if(flag==1)
printf("%d Foundn", k);
else
/* If Item Not Found */
{
travel=*first;
while(travel->next!=*first)
travel=travel->next;
newn->next=travel->next;
travel->next=newn;
printf("k=%d Not Found In The List So It Is Inserted As Last Noden", k);
}
P a g e |7

Circular List

Write A C Routine That Concatenate Two Circular List.
/* Concatenate two lists. */
#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *next;
};
typedef struct node NODE;
void c_ins_first(NODE**, int);
void display(NODE*);
void concat(NODE**, NODE**);
int main()
{
NODE *first1=NULL;
NODE *first2=NULL;
int choice, item;
for(;;)
{
printf("Stack Menun");
printf("1.In First List To Insert Frontn");
printf("2.In Second List To Insert Frontn");
printf("3.To Display First Listn");
printf("4.To Display Second Listn");
printf("5.To Concate Both List & To Displayn");
printf("6.Exitn");
printf("Enter U R Choicen");
scanf("%d", &choice);
printf("nn");
switch(choice)
{
case 1 :

printf("First Listn");
printf("Enter The Item To Insertn");
scanf("%d", &item);
printf("nn");
c_ins_first(&first1, item);
break;

Ashok R
P a g e |8

Circular List

case 2 : printf("Second Listn");
printf("Enter The Item To Insertn");
scanf("%d", &item);
printf("nn");
c_ins_first(&first2, item);
break;
case 3 : printf("Contents Of First Listn");
display(first1);
break;
case 4 : printf("Contents Of Second Listn");
display(first2);
break;
case 5 : printf("Concating List Wait....n");
concat(&first1, &first2);
printf("After Concating Elements In List Isn");
display(first1);
break;
default : exit(0);

}

}
}
return 1;

void c_ins_first(NODE **first, int item)
{
NODE *newn, *travel;
newn=(NODE*)malloc(sizeof(NODE));
newn->info=item;
if(*first==NULL)
{
newn->next=newn;
*first=newn;
}
else
{
travel=*first;
while(travel->next!=*first)
travel=travel->next;
newn->next=*first;
travel->next=newn;
*first=newn;
}
}

Ashok R
P a g e |9

Circular List

void display(NODE *first)
{
NODE *travel;
travel=first;
if(first==NULL)
{
printf("List Is Emptynn");
}
else
{
while(travel->next!=first)
{
printf("%dn", travel->info);
travel=travel->next;
}
printf("%dnn", travel->info);
}
}

void concat(NODE **first1, NODE **first2)
{
NODE *temp, *travel;
if(*first1==NULL)
*first1=*first2;
else
{
temp=*first1;
while(temp->next!=*first1)
temp=temp->next; /* Now temp Is Pointing To Last Node Of A First Circular List */
travel=*first2;
while(travel->next!=*first2)
travel=travel->next; /*Now travel Is Pointing To Last Node Of A Second Circular List */

}

}

temp->next=*first2;
travel->next=*first1;

Ashok R

More Related Content

PPTX
Circular linked list
PPTX
Single linked list
PPTX
Double linked list
DOC
Final ds record
DOCX
Linked list imp of list
Circular linked list
Single linked list
Double linked list
Final ds record
Linked list imp of list

What's hot (20)

DOCX
C program to implement linked list using array abstract data type
DOCX
Stack prgs
PPT
Doublylinklist
PPTX
Double linked list
PDF
Datastructures asignment
PDF
The Ring programming language version 1.8 book - Part 86 of 202
PDF
The Ring programming language version 1.6 book - Part 84 of 189
PDF
Railway reservation system
DOC
C program to insert a node in doubly linked list
PDF
The Ring programming language version 1.4.1 book - Part 22 of 31
PDF
C++ programs
PDF
Data structures stacks
DOCX
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DOCX
PL/SQL Blocks
DOCX
DataStructures notes
PPTX
Lambda выражения и Java 8
C program to implement linked list using array abstract data type
Stack prgs
Doublylinklist
Double linked list
Datastructures asignment
The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.6 book - Part 84 of 189
Railway reservation system
C program to insert a node in doubly linked list
The Ring programming language version 1.4.1 book - Part 22 of 31
C++ programs
Data structures stacks
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
PL/SQL Blocks
DataStructures notes
Lambda выражения и Java 8
Ad

Viewers also liked (19)

PDF
10 generics a-4_in_1
PPTX
Data structures1
PDF
It6601 mobile computing unit 4 questions
PPTX
Stack in Sata Structure
PDF
IT6601 Mobile Computing
PPTX
IT6601 MOBILE COMPUTING UNIT1
PPSX
Data Structure (Circular Linked List)
PDF
IT6601 MOBILE COMPUTING
PPTX
It6601 mobile computing unit 5
PPTX
It6601 mobile computing unit 3
PDF
IT6601 MOBILE COMPUTING
PDF
IT6601 MOBILE COMPUTING
PPTX
It6601 mobile computing unit 4
PPTX
It6601 mobile computing unit2
PPT
Linked list
PDF
IT6601 MOBILE COMPUTING
PDF
DSA-2012-Lect00
PPT
Circular linked list
PPT
Fundamentals of data structures
10 generics a-4_in_1
Data structures1
It6601 mobile computing unit 4 questions
Stack in Sata Structure
IT6601 Mobile Computing
IT6601 MOBILE COMPUTING UNIT1
Data Structure (Circular Linked List)
IT6601 MOBILE COMPUTING
It6601 mobile computing unit 5
It6601 mobile computing unit 3
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
It6601 mobile computing unit 4
It6601 mobile computing unit2
Linked list
IT6601 MOBILE COMPUTING
DSA-2012-Lect00
Circular linked list
Fundamentals of data structures
Ad

Similar to Data structure circular list (20)

PPTX
Data structure.pptx
PPT
CIRCULAR LINKED LIST IN DATA STRUCTURES CLL
PPTX
Linked list data structures and algorithms
PDF
Data structure singly linked list programs VTU Exams
PPTX
Circular linked list
DOCX
DS UNIT4_OTHER LIST STRUCTURES.docx
PPTX
Deleting a node from the list(SINGLE LINKED LIST)
PDF
Document on Linked List as a presentation
PDF
Document on Linked List as a presentation
PPTX
Circular link list.ppt
PPTX
circularlinklist-190205164051.pptx
PDF
Circular linked list
PPTX
Circular Linked List in Data Structures Design
PPT
Unit ii(dsc++)
PPTX
Data structure and algorithm list structures
PPTX
LINKED LIST.pptx
PPTX
Circular linked list.pptx
PDF
#includeiostream#includecstdio#includecstdlibusing names.pdf
PPTX
CIRCULAR LINKED LIST _
Data structure.pptx
CIRCULAR LINKED LIST IN DATA STRUCTURES CLL
Linked list data structures and algorithms
Data structure singly linked list programs VTU Exams
Circular linked list
DS UNIT4_OTHER LIST STRUCTURES.docx
Deleting a node from the list(SINGLE LINKED LIST)
Document on Linked List as a presentation
Document on Linked List as a presentation
Circular link list.ppt
circularlinklist-190205164051.pptx
Circular linked list
Circular Linked List in Data Structures Design
Unit ii(dsc++)
Data structure and algorithm list structures
LINKED LIST.pptx
Circular linked list.pptx
#includeiostream#includecstdio#includecstdlibusing names.pdf
CIRCULAR LINKED LIST _

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Classroom Observation Tools for Teachers
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Business Ethics Teaching Materials for college
Renaissance Architecture: A Journey from Faith to Humanism
Classroom Observation Tools for Teachers
Module 4: Burden of Disease Tutorial Slides S2 2025
102 student loan defaulters named and shamed – Is someone you know on the list?
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
TR - Agricultural Crops Production NC III.pdf
Complications of Minimal Access Surgery at WLH
Microbial disease of the cardiovascular and lymphatic systems
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Week 4 Term 3 Study Techniques revisited.pptx
Cell Structure & Organelles in detailed.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Business Ethics Teaching Materials for college

Data structure circular list

  • 1. P a g e |1 Circular List /* WAP 1. Insert A Node Into Front Of A Circular Linked List. 2. Delete A Node From The Front End. 3. Display. */ #include<stdio.h> #include<stdlib.h> struct node { int info; struct node *next; }; typedef struct node NODE; void c_ins_first(NODE**, int); int c_del_first(NODE**); void c_display(NODE*); int main() { NODE *first=NULL; int choice, item; for(;;) { printf("Circular Linked Listn"); printf("1.Insert Frontn"); printf("2.Delete Frontn"); printf("3.Displayn"); printf("4.Exitn"); printf("Enter U R Choicen"); scanf("%d", &choice); printf("nn"); switch(choice) { case 1 : printf("Enter The Item To Insertn"); scanf("%d", &item); printf("nn"); c_ins_first(&first, item); break; case 2 : item=c_del_first(&first); if(item!='0') printf("Deleted Element Is %dnn", item); break; case 3 : printf("Contents Of Stack Aren"); c_display(first); break; default : exit(0); Ashok R
  • 2. P a g e |2 } Circular List } } return 1; void c_ins_first(NODE **first, int item) { NODE *newn, *travel; newn=(NODE*)malloc(sizeof(NODE)); newn->info=item; if(*first==NULL) { newn->next=newn; *first=newn; } else { travel=*first; while(travel->next!=*first) travel=travel->next; newn->next=*first; travel->next=newn; *first=newn; } } int c_del_first(NODE **first) { int item; NODE *travel, *temp; if(*first==NULL) { printf("List Is Emptynn"); return('0'); } temp=*first; travel=*first; if(temp->next==*first) /* If There Is Only One Node Delete It */ { item=temp->info; *first=NULL; free(temp); return item; } Ashok R
  • 3. P a g e |3 } Circular List while(travel->next!=*first) /* List Contain More Than One Nodes */ travel=travel->next; item=temp->info; *first=temp->next; travel->next=temp->next; /* OR travel->next=*first */ free(temp); return item; void c_display(NODE *first) { NODE *travel; travel=first; if(first==NULL) { printf("List Is Emptynn"); } else { while(travel->next!=first) { printf("%dn", travel->info); travel=travel->next; } printf("%dnn", travel->info); } } Ashok R
  • 4. P a g e |4 Circular List /* Insert Node Last */ case 4 : printf("Enter The Item To Insertn"); scanf("%d", &item); printf("nn"); c_ins_last(&first, item); break; void c_ins_last(NODE **first, int item) { NODE *newn, *travel; newn=(NODE*)malloc(sizeof(NODE)); newn->info=item; if(*first==NULL) { newn->next=newn; *first=newn; } else { travel=*first; while(travel->next!=*first) travel=travel->next; newn->next=travel->next; travel->next=newn; } } Ashok R
  • 5. P a g e |5 Circular List Delete Last case 5 : item=c_del_last(&first); if(item!='0') printf("Deleted Element Is %dnn", item); break; int c_del_last(NODE **first) { int item; NODE *travel, *temp; if(*first==NULL) { printf("List Is Emptynn"); return('0'); } temp=*first; travel=*first; if(temp->next==*first) /* If There Is Only One Node Delete It */ { item=temp->info; *first=NULL; free(temp); return item; } while(travel->next!=*first) /* List Contain More Than One Nodes */ { temp=travel; travel=travel->next; } item=travel->info; temp->next=travel->next; free(travel); return item; } Ashok R
  • 6. P a g e |6 Circular List Ashok R CIRCULAR LIST. WRITE A PROGRAM TO SEARCH A NODE WITH A VALUE K , IF IT IS NOT FOUND THEN INSERT VALUE AS LAST NODE. void c_ins_k(NODE **first, int k) { NODE *newn, *travel, *temp; int flag=0; newn=(NODE*)malloc(sizeof(NODE)); newn->info=k; travel=*first; if(*first==NULL) { /* List Is Empty, So Element k Is Inserted As Last Node */ newn->next=newn; *first=newn; } else if(travel->info==k) /* Item Found At 1st Postion */ flag=1; else { temp=*first; /* Initially Pointing To 1st Item In A List */ travel=temp->next; /* Initially Pointing To 2nd Item In A List */ while(travel!=*first && flag==0) { if(travel->info==k) { flag=1; break; } travel=travel->next; } } } if(flag==1) printf("%d Foundn", k); else /* If Item Not Found */ { travel=*first; while(travel->next!=*first) travel=travel->next; newn->next=travel->next; travel->next=newn; printf("k=%d Not Found In The List So It Is Inserted As Last Noden", k); }
  • 7. P a g e |7 Circular List Write A C Routine That Concatenate Two Circular List. /* Concatenate two lists. */ #include<stdio.h> #include<stdlib.h> struct node { int info; struct node *next; }; typedef struct node NODE; void c_ins_first(NODE**, int); void display(NODE*); void concat(NODE**, NODE**); int main() { NODE *first1=NULL; NODE *first2=NULL; int choice, item; for(;;) { printf("Stack Menun"); printf("1.In First List To Insert Frontn"); printf("2.In Second List To Insert Frontn"); printf("3.To Display First Listn"); printf("4.To Display Second Listn"); printf("5.To Concate Both List & To Displayn"); printf("6.Exitn"); printf("Enter U R Choicen"); scanf("%d", &choice); printf("nn"); switch(choice) { case 1 : printf("First Listn"); printf("Enter The Item To Insertn"); scanf("%d", &item); printf("nn"); c_ins_first(&first1, item); break; Ashok R
  • 8. P a g e |8 Circular List case 2 : printf("Second Listn"); printf("Enter The Item To Insertn"); scanf("%d", &item); printf("nn"); c_ins_first(&first2, item); break; case 3 : printf("Contents Of First Listn"); display(first1); break; case 4 : printf("Contents Of Second Listn"); display(first2); break; case 5 : printf("Concating List Wait....n"); concat(&first1, &first2); printf("After Concating Elements In List Isn"); display(first1); break; default : exit(0); } } } return 1; void c_ins_first(NODE **first, int item) { NODE *newn, *travel; newn=(NODE*)malloc(sizeof(NODE)); newn->info=item; if(*first==NULL) { newn->next=newn; *first=newn; } else { travel=*first; while(travel->next!=*first) travel=travel->next; newn->next=*first; travel->next=newn; *first=newn; } } Ashok R
  • 9. P a g e |9 Circular List void display(NODE *first) { NODE *travel; travel=first; if(first==NULL) { printf("List Is Emptynn"); } else { while(travel->next!=first) { printf("%dn", travel->info); travel=travel->next; } printf("%dnn", travel->info); } } void concat(NODE **first1, NODE **first2) { NODE *temp, *travel; if(*first1==NULL) *first1=*first2; else { temp=*first1; while(temp->next!=*first1) temp=temp->next; /* Now temp Is Pointing To Last Node Of A First Circular List */ travel=*first2; while(travel->next!=*first2) travel=travel->next; /*Now travel Is Pointing To Last Node Of A Second Circular List */ } } temp->next=*first2; travel->next=*first1; Ashok R