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

What's hot

C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
loyola ICAM college of engineering and technology
 
Stack prgs
Stack prgsStack prgs
Stack prgs
Ssankett Negi
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Double linked list
Double linked listDouble linked list
Double linked list
raviahuja11
 
Avl tree
Avl treeAvl tree
week-15x
week-15xweek-15x
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189
Mahmoud Samir Fayed
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation system
Prashant Sharma
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
Sourav Gayen
 
The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31
Mahmoud Samir Fayed
 
C++ programs
C++ programsC++ programs
C++ programs
Mukund Gandrakota
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
maamir farooq
 
Doc1
Doc1Doc1
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
week-17x
week-17xweek-17x
PL/SQL Blocks
PL/SQL BlocksPL/SQL Blocks
PL/SQL Blocks
Anar Godjaev
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
Lambda выражения и Java 8
Lambda выражения и Java 8Lambda выражения и Java 8
Lambda выражения и Java 8
Alex Tumanoff
 

What's hot (20)

C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Avl tree
Avl treeAvl tree
Avl tree
 
week-15x
week-15xweek-15x
week-15x
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202The Ring programming language version 1.8 book - Part 86 of 202
The Ring programming language version 1.8 book - Part 86 of 202
 
The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189
 
Railway reservation system
Railway reservation systemRailway reservation system
Railway reservation system
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31
 
C++ programs
C++ programsC++ programs
C++ programs
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Doc1
Doc1Doc1
Doc1
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
week-17x
week-17xweek-17x
week-17x
 
PL/SQL Blocks
PL/SQL BlocksPL/SQL Blocks
PL/SQL Blocks
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Lambda выражения и Java 8
Lambda выражения и Java 8Lambda выражения и Java 8
Lambda выражения и Java 8
 

Viewers also liked

10 generics a-4_in_1
10 generics a-4_in_110 generics a-4_in_1
10 generics a-4_in_1
arasforever
 
Data structures1
Data structures1Data structures1
Data structures1
Parthipan Parthi
 
It6601 mobile computing unit 4 questions
It6601 mobile computing unit 4 questionsIt6601 mobile computing unit 4 questions
It6601 mobile computing unit 4 questions
RMK ENGINEERING COLLEGE, CHENNAI
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
Muhazzab Chouhadry
 
IT6601 Mobile Computing
IT6601 Mobile  Computing IT6601 Mobile  Computing
IT6601 Mobile Computing
Ams Prabhu
 
IT6601 MOBILE COMPUTING UNIT1
IT6601 MOBILE COMPUTING UNIT1IT6601 MOBILE COMPUTING UNIT1
IT6601 MOBILE COMPUTING UNIT1
RMK ENGINEERING COLLEGE, CHENNAI
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
Kathirvel Ayyaswamy
 
It6601 mobile computing unit 5
It6601 mobile computing unit 5It6601 mobile computing unit 5
It6601 mobile computing unit 5
RMK ENGINEERING COLLEGE, CHENNAI
 
It6601 mobile computing unit 3
It6601 mobile computing unit 3It6601 mobile computing unit 3
It6601 mobile computing unit 3
RMK ENGINEERING COLLEGE, CHENNAI
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
Kathirvel Ayyaswamy
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
Kathirvel Ayyaswamy
 
It6601 mobile computing unit 4
It6601 mobile computing unit 4It6601 mobile computing unit 4
It6601 mobile computing unit 4
RMK ENGINEERING COLLEGE, CHENNAI
 
It6601 mobile computing unit2
It6601 mobile computing unit2It6601 mobile computing unit2
It6601 mobile computing unit2
RMK ENGINEERING COLLEGE, CHENNAI
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
Kathirvel Ayyaswamy
 
DSA-2012-Lect00
DSA-2012-Lect00DSA-2012-Lect00
DSA-2012-Lect00
Haitham El-Ghareeb
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
dchuynh
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Niraj Agarwal
 

Viewers also liked (19)

10 generics a-4_in_1
10 generics a-4_in_110 generics a-4_in_1
10 generics a-4_in_1
 
Data structures1
Data structures1Data structures1
Data structures1
 
It6601 mobile computing unit 4 questions
It6601 mobile computing unit 4 questionsIt6601 mobile computing unit 4 questions
It6601 mobile computing unit 4 questions
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
IT6601 Mobile Computing
IT6601 Mobile  Computing IT6601 Mobile  Computing
IT6601 Mobile Computing
 
IT6601 MOBILE COMPUTING UNIT1
IT6601 MOBILE COMPUTING UNIT1IT6601 MOBILE COMPUTING UNIT1
IT6601 MOBILE COMPUTING UNIT1
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
 
It6601 mobile computing unit 5
It6601 mobile computing unit 5It6601 mobile computing unit 5
It6601 mobile computing unit 5
 
It6601 mobile computing unit 3
It6601 mobile computing unit 3It6601 mobile computing unit 3
It6601 mobile computing unit 3
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
 
It6601 mobile computing unit 4
It6601 mobile computing unit 4It6601 mobile computing unit 4
It6601 mobile computing unit 4
 
It6601 mobile computing unit2
It6601 mobile computing unit2It6601 mobile computing unit2
It6601 mobile computing unit2
 
Linked list
Linked listLinked list
Linked list
 
IT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTINGIT6601 MOBILE COMPUTING
IT6601 MOBILE COMPUTING
 
DSA-2012-Lect00
DSA-2012-Lect00DSA-2012-Lect00
DSA-2012-Lect00
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 

Similar to Data structure circular list

Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
iCreateWorld
 
Linked lists
Linked listsLinked lists
Linked lists
George Scott IV
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
brijmote
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
clarkjanyce
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
VeerannaKotagi1
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
Chaitanya Kn
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
connellalykshamesb60
 
Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdf
meerobertsonheyde608
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
GordonpACKellyb
 
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdfPlease finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
fortmdu
 
Linked lists
Linked listsLinked lists

Similar to Data structure circular list (20)

Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
 
Linked lists
Linked listsLinked lists
Linked lists
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdf
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
 
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdfPlease finish the int LLInsert function.typedef struct STUDENT {.pdf
Please finish the int LLInsert function.typedef struct STUDENT {.pdf
 
Linked lists
Linked listsLinked lists
Linked lists
 

Recently uploaded

MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 

Recently uploaded (20)

MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 

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