SlideShare une entreprise Scribd logo
1  sur  18
CIRCULAR LINKED LIST
A Menu Driven Program In C
The Basic Declarations
#include<stdio.h>
#include<stdlib.h>
void mainmenu(), create(), display(), insert(), insert_first(), insert_between(),
insert_end(), deletion(), delete_first(), delete_position(), delete_end(),
sort(), reverse(), find();
int count();
struct node
{
int info;
struct node *link;
};
typedef struct node NODE;
NODE *start=NULL;
int main()
{
mainmenu();
}
The Mainmenu Function
void mainmenu()
{
int choice,x;
while(1)
{
printf("n----MAIN MENU----n");
printf("1. Create.n");
printf("2. Display.n");
printf("3. Insert.n");
printf("4. Count.n");
printf("5. Delete.n");
printf("6. Sorting.n");
printf("7. Reverse.n");
printf("8. Find.n");
printf("9. Exit.n");
printf("Enter choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: create();
break;
case 2: display();
break;
case 3: insert();
break;
case 4: x=count();
printf("The number of elements are %d",x);
break;
case 5: deletion();
break;
case 6: sort();
break;
case 7: reverse();
break;
case 8: find();
break;
case 9: exit(0);
break;
default: printf("Enter a valid choice.");
}
}
}
Creation Of Nodes
void create()
{
NODE *temp, *traverse;
int iData;
printf("Enter an integer value: ");
scanf("%d",&iData);
temp=(NODE *)malloc(sizeof(NODE));
temp->info=iData;
temp->link=NULL;
if(start==NULL)
{
start=temp;
start->link=temp;
}
else
{
traverse=start;
while(traverse->link!=start)
{
traverse=traverse->link;
}
traverse->link=temp;
temp->link=start;
}
}
Display Function
void display()
{
if (start==NULL)
printf("nList is emptyn");
else
{
NODE *traverse;
traverse=start;
printf("The linked list is: ");
printf("%d ",traverse->info);
while (traverse->link!=start)
{
traverse=traverse->link;
printf("%d ",traverse->info);
}
}
}
The Insert Menu
void insert()
{
int choice;
while(1)
{
printf("n---Insert Menu---n");
printf("1. Insert at first position.n");
printf("2. Insert in between.n");
printf("3. Insert at the end.n");
printf("4. Go to main menun");
printf("5. Exitn");
printf("Enter choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: insert_first();
break;
case 2: insert_between();
break;
case 3: insert_end();
break;
case 4: mainmenu();
break;
case 5: exit(0);
break;
default: printf("Enter a valid choice.");
}
}
}
Insertion Of Node In The First Place
void insert_first()
{
if(start==NULL)
{
printf("List is empty. Create as the first node.n");
create();
}
else
{
NODE *temp,*traverse;
int iData;
printf("Enter an integer value: ");
scanf("%d",&iData);
temp=(NODE *)malloc(sizeof(NODE));
temp->info=iData;
traverse=start;
while(traverse->link!=start)
{
traverse=traverse->link;
}
traverse->link=temp;
temp->link=start;
start=temp;
}
display();
}
Insert At A Particular Position
void insert_between()
{
if(start==NULL)
{
printf("List is empty. Create as the first node.n");
create();
}
else
{
NODE *temp, *traverse;
int iLoop,iPosition,iCount,iData;
printf("Enter the position where you want to insert: ");
scanf("%d",&iPosition);
iCount=count();
if(iPosition>iCount)
{
printf("There are only %d elements.",iCount);
}
else
{
traverse=start;
printf("Enter an integer value: ");
scanf("%d",&iData);
for(iLoop=0;iLoop<iPosition-2;iLoop++)
{
traverse=traverse->link;
}
temp=(NODE*)malloc(sizeof(NODE));
temp->info=iData;
temp->link=traverse->link;
traverse->link=temp;
}
}
display();
}
Insert Node At The End
void insert_end()
{
if(start==NULL)
{
printf("List is empty. Create as the first node.n");
create();
}
else
{
create();
}
display();
}
Counting of the nodes
int count()
{
NODE *traverse;
int iCount=0;
if (start == NULL)
{
printf("nList is empty.n");
return iCount;
}
else
{
traverse = start;
if(traverse->link==start)
{
iCount=1;
return iCount;
}
else
{
iCount=1;
while (traverse->link != start)
{
iCount++;
traverse = traverse->link;
}
return iCount;
}
}
}
The Delete Menu
void deletion()
{
int choice;
while(1)
{
printf("n---Delete Menu---n");
printf("1. Delete first node.n");
printf("2. Delete last node.n");
printf("3. Delete by position.n");
printf("4. Go to main menun");
printf("5. Exitn");
printf("Enter choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: delete_first();
break;
case 2: delete_end();
break;
case 3: delete_position();
break;
case 4: mainmenu();
break;
case 5: exit(0);
break;
default: printf("Enter a valid choice.");
}
}
}
Delete Node From The First Position
void delete_first()
{
if (start==NULL)
{
printf("nList is empty.n");
}
else
{
int iCount;
iCount=count();
if(iCount==1)
{
start=NULL;
free(start);
}
else
{
NODE *delete_node,*traverse;
traverse=start;
while(traverse->link!=start)
{
traverse=traverse->link;
}
delete_node=start;
start=start->link;
traverse->link=start;
free(delete_node);
}
display();
}
}
Delete Node From The End
void delete_end()
{
if (start==NULL)
{
printf("nList is empty.n");
}
else
{
int iCount;
iCount=count();
if(iCount==1)
{
start=NULL;
free(start);
}
else
{
NODE *traverse, *delete_node;
traverse=start;
while(traverse->link->link!=start)
{
traverse=traverse->link;
}
delete_node=traverse->link;
traverse->link=start;
free(delete_node);
}
display();
}
}
Delete At A Particular Position
void delete_position()
{
if (start==NULL)
{
printf("nList is empty.n");
}
else
{
int iCount,iPosition,iLoop;
printf("Enter the position to be deleted: ");
scanf("%d",&iPosition);
iCount=count();
if(iPosition>iCount)
{
printf("There are only %d elements.",iCount);
}
else
{
if(iCount==1)
{
start=NULL;
free(start);
}
else
{
NODE *delete_node, *traverse;
traverse=start;
for(iLoop=0;iLoop<iPosition-2;iLoop++)
{
traverse=traverse->link;
}
delete_node=traverse->link;
traverse->link=delete_node->link;
free(delete_node);
}
display();
}
}
}
Sorting Of The List
void sort()
{
NODE *traverse1, *traverse2;
int iOuter_Loop,iInner_Loop,iCount,temp;
iCount=count();
for(iOuter_Loop=0;iOuter_Loop<iCount-1;iOuter_Loop++)
{
traverse1=start;
traverse2=traverse1->link;
for(iInner_Loop=iOuter_Loop+1;iInner_Loop<iCount;iInner_Loop++)
{
if(traverse1->info>traverse2->info)
{
temp=traverse1->info;
traverse1->info=traverse2->info;
traverse2->info=temp;
}
traverse1=traverse1->link;
traverse2=traverse2->link;
}
}
display();
}
Reversal Of The List
void reverse()
{
NODE *previous, *current, *next;
previous=start;
current=previous->link;
next=current->link;
current->link=previous;
while(next!=start)
{
previous=current;
current=next;
next=next->link;
current->link=previous;
}
start->link=current;
start=current;
display();
}
Searching Of An Element
void find()
{
int iData;
NODE *traverse;
printf("Enter a number to be searched: ");
scanf("%d",&iData);
traverse=start;
while(traverse->link!=start)
{
if(traverse->info==iData)
{
printf("Element found.");
return;
}
else
{
traverse=traverse->link;
}
}
if(traverse->info==iData)
{
printf("Element found.");
return;
}
else
{
printf("Element not found.");
}
}
Presented By:
Sayantan Sur
Thank You

Contenu connexe

Tendances (20)

C++ programs
C++ programsC++ programs
C++ programs
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
week-13x
week-13xweek-13x
week-13x
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
 
งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
week-14x
week-14xweek-14x
week-14x
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
week-17x
week-17xweek-17x
week-17x
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
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
 
ภาษาซี
ภาษาซีภาษาซี
ภาษาซี
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 

En vedette

Circular linked list
Circular linked listCircular linked list
Circular linked listdchuynh
 
Presentation on circular linked list
Presentation on circular linked listPresentation on circular linked list
Presentation on circular linked listmehak1996
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)Durga Devi
 
Circular linked list
Circular linked listCircular linked list
Circular linked listmaamir farooq
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structureeShikshak
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked listsstudent
 

En vedette (17)

Circular linked list
Circular linked listCircular linked list
Circular linked list
 
circular linked list
circular linked listcircular linked list
circular linked list
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
 
Presentation on circular linked list
Presentation on circular linked listPresentation on circular linked list
Presentation on circular linked list
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Applications of queue
Applications of queueApplications of queue
Applications of queue
 
Team 10
Team 10Team 10
Team 10
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Linked list
Linked listLinked list
Linked list
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 

Similaire à Circular linked list

Similaire à Circular linked list (20)

Single linked list
Single linked listSingle linked list
Single linked list
 
C program
C programC program
C program
 
Data Structures : array operations in c program
Data Structures : array operations in c program Data Structures : array operations in c program
Data Structures : array operations in c program
 
Array list
Array listArray list
Array list
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Array menu
Array menuArray menu
Array menu
 
C basics
C basicsC basics
C basics
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
week-21x
week-21xweek-21x
week-21x
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
week-15x
week-15xweek-15x
week-15x
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
array implementation
 array implementation array implementation
array implementation
 

Plus de Sayantan Sur

Image Encryption and Compression
Image Encryption and Compression Image Encryption and Compression
Image Encryption and Compression Sayantan Sur
 
Decision Support System(DSS)
Decision Support System(DSS)Decision Support System(DSS)
Decision Support System(DSS)Sayantan Sur
 
International Terrorism
International Terrorism International Terrorism
International Terrorism Sayantan Sur
 

Plus de Sayantan Sur (8)

Image Encryption and Compression
Image Encryption and Compression Image Encryption and Compression
Image Encryption and Compression
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
Decision Support System(DSS)
Decision Support System(DSS)Decision Support System(DSS)
Decision Support System(DSS)
 
Network Security
Network SecurityNetwork Security
Network Security
 
Visual Studio IDE
Visual Studio IDEVisual Studio IDE
Visual Studio IDE
 
Ethical Hacking
Ethical HackingEthical Hacking
Ethical Hacking
 
Phising
PhisingPhising
Phising
 
International Terrorism
International Terrorism International Terrorism
International Terrorism
 

Dernier

Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 

Dernier (20)

Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 

Circular linked list

  • 1. CIRCULAR LINKED LIST A Menu Driven Program In C
  • 2. The Basic Declarations #include<stdio.h> #include<stdlib.h> void mainmenu(), create(), display(), insert(), insert_first(), insert_between(), insert_end(), deletion(), delete_first(), delete_position(), delete_end(), sort(), reverse(), find(); int count(); struct node { int info; struct node *link; }; typedef struct node NODE; NODE *start=NULL; int main() { mainmenu(); }
  • 3. The Mainmenu Function void mainmenu() { int choice,x; while(1) { printf("n----MAIN MENU----n"); printf("1. Create.n"); printf("2. Display.n"); printf("3. Insert.n"); printf("4. Count.n"); printf("5. Delete.n"); printf("6. Sorting.n"); printf("7. Reverse.n"); printf("8. Find.n"); printf("9. Exit.n"); printf("Enter choice: "); scanf("%d",&choice); switch(choice) { case 1: create(); break; case 2: display(); break; case 3: insert(); break; case 4: x=count(); printf("The number of elements are %d",x); break; case 5: deletion(); break; case 6: sort(); break; case 7: reverse(); break; case 8: find(); break; case 9: exit(0); break; default: printf("Enter a valid choice."); } } }
  • 4. Creation Of Nodes void create() { NODE *temp, *traverse; int iData; printf("Enter an integer value: "); scanf("%d",&iData); temp=(NODE *)malloc(sizeof(NODE)); temp->info=iData; temp->link=NULL; if(start==NULL) { start=temp; start->link=temp; } else { traverse=start; while(traverse->link!=start) { traverse=traverse->link; } traverse->link=temp; temp->link=start; } }
  • 5. Display Function void display() { if (start==NULL) printf("nList is emptyn"); else { NODE *traverse; traverse=start; printf("The linked list is: "); printf("%d ",traverse->info); while (traverse->link!=start) { traverse=traverse->link; printf("%d ",traverse->info); } } }
  • 6. The Insert Menu void insert() { int choice; while(1) { printf("n---Insert Menu---n"); printf("1. Insert at first position.n"); printf("2. Insert in between.n"); printf("3. Insert at the end.n"); printf("4. Go to main menun"); printf("5. Exitn"); printf("Enter choice: "); scanf("%d",&choice); switch(choice) { case 1: insert_first(); break; case 2: insert_between(); break; case 3: insert_end(); break; case 4: mainmenu(); break; case 5: exit(0); break; default: printf("Enter a valid choice."); } } }
  • 7. Insertion Of Node In The First Place void insert_first() { if(start==NULL) { printf("List is empty. Create as the first node.n"); create(); } else { NODE *temp,*traverse; int iData; printf("Enter an integer value: "); scanf("%d",&iData); temp=(NODE *)malloc(sizeof(NODE)); temp->info=iData; traverse=start; while(traverse->link!=start) { traverse=traverse->link; } traverse->link=temp; temp->link=start; start=temp; } display(); }
  • 8. Insert At A Particular Position void insert_between() { if(start==NULL) { printf("List is empty. Create as the first node.n"); create(); } else { NODE *temp, *traverse; int iLoop,iPosition,iCount,iData; printf("Enter the position where you want to insert: "); scanf("%d",&iPosition); iCount=count(); if(iPosition>iCount) { printf("There are only %d elements.",iCount); } else { traverse=start; printf("Enter an integer value: "); scanf("%d",&iData); for(iLoop=0;iLoop<iPosition-2;iLoop++) { traverse=traverse->link; } temp=(NODE*)malloc(sizeof(NODE)); temp->info=iData; temp->link=traverse->link; traverse->link=temp; } } display(); }
  • 9. Insert Node At The End void insert_end() { if(start==NULL) { printf("List is empty. Create as the first node.n"); create(); } else { create(); } display(); }
  • 10. Counting of the nodes int count() { NODE *traverse; int iCount=0; if (start == NULL) { printf("nList is empty.n"); return iCount; } else { traverse = start; if(traverse->link==start) { iCount=1; return iCount; } else { iCount=1; while (traverse->link != start) { iCount++; traverse = traverse->link; } return iCount; } } }
  • 11. The Delete Menu void deletion() { int choice; while(1) { printf("n---Delete Menu---n"); printf("1. Delete first node.n"); printf("2. Delete last node.n"); printf("3. Delete by position.n"); printf("4. Go to main menun"); printf("5. Exitn"); printf("Enter choice: "); scanf("%d",&choice); switch(choice) { case 1: delete_first(); break; case 2: delete_end(); break; case 3: delete_position(); break; case 4: mainmenu(); break; case 5: exit(0); break; default: printf("Enter a valid choice."); } } }
  • 12. Delete Node From The First Position void delete_first() { if (start==NULL) { printf("nList is empty.n"); } else { int iCount; iCount=count(); if(iCount==1) { start=NULL; free(start); } else { NODE *delete_node,*traverse; traverse=start; while(traverse->link!=start) { traverse=traverse->link; } delete_node=start; start=start->link; traverse->link=start; free(delete_node); } display(); } }
  • 13. Delete Node From The End void delete_end() { if (start==NULL) { printf("nList is empty.n"); } else { int iCount; iCount=count(); if(iCount==1) { start=NULL; free(start); } else { NODE *traverse, *delete_node; traverse=start; while(traverse->link->link!=start) { traverse=traverse->link; } delete_node=traverse->link; traverse->link=start; free(delete_node); } display(); } }
  • 14. Delete At A Particular Position void delete_position() { if (start==NULL) { printf("nList is empty.n"); } else { int iCount,iPosition,iLoop; printf("Enter the position to be deleted: "); scanf("%d",&iPosition); iCount=count(); if(iPosition>iCount) { printf("There are only %d elements.",iCount); } else { if(iCount==1) { start=NULL; free(start); } else { NODE *delete_node, *traverse; traverse=start; for(iLoop=0;iLoop<iPosition-2;iLoop++) { traverse=traverse->link; } delete_node=traverse->link; traverse->link=delete_node->link; free(delete_node); } display(); } } }
  • 15. Sorting Of The List void sort() { NODE *traverse1, *traverse2; int iOuter_Loop,iInner_Loop,iCount,temp; iCount=count(); for(iOuter_Loop=0;iOuter_Loop<iCount-1;iOuter_Loop++) { traverse1=start; traverse2=traverse1->link; for(iInner_Loop=iOuter_Loop+1;iInner_Loop<iCount;iInner_Loop++) { if(traverse1->info>traverse2->info) { temp=traverse1->info; traverse1->info=traverse2->info; traverse2->info=temp; } traverse1=traverse1->link; traverse2=traverse2->link; } } display(); }
  • 16. Reversal Of The List void reverse() { NODE *previous, *current, *next; previous=start; current=previous->link; next=current->link; current->link=previous; while(next!=start) { previous=current; current=next; next=next->link; current->link=previous; } start->link=current; start=current; display(); }
  • 17. Searching Of An Element void find() { int iData; NODE *traverse; printf("Enter a number to be searched: "); scanf("%d",&iData); traverse=start; while(traverse->link!=start) { if(traverse->info==iData) { printf("Element found."); return; } else { traverse=traverse->link; } } if(traverse->info==iData) { printf("Element found."); return; } else { printf("Element not found."); } }