SlideShare a Scribd company logo
DOUBLE 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
{
struct node *prev;
int info;
struct node *next;
};
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;
temp=(NODE*)malloc(sizeof(NODE));
temp->prev=NULL;
temp->next=NULL;
printf("Enter an integer value: ");
scanf("%d",&iData);
temp->info=iData;
if(start==NULL)
{
start=temp;
}
else
{
traverse=start;
while(traverse->next!=NULL)
{
traverse=traverse->next;
}
traverse->next=temp;
temp->prev=traverse;
}
}
Display Of The Nodes
void display()
{
NODE *traverse;
if(start==NULL)
{
printf("There are no nodes to be displayed. The list is
empty.n");
}
else
{
traverse=start;
printf("The linked list is: ");
while(traverse!=NULL)
{
printf("%d ",traverse->info);
traverse=traverse->next;
}
}
}
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.");
}
}
}
Insert Node At The First Position
void insert_first()
{
NODE *temp;
if(start==NULL)
{
printf("List is empty. Create as the first node.n");
create();
}
else
{
int iData;
temp=(NODE *)malloc(sizeof(NODE));
temp->prev=NULL;
temp->next=NULL;
printf("Enter an integer value: ");
scanf("%d",&iData);
temp->info=iData;
start->prev=temp;
temp->next=start;
start=temp;
printf("Node inserted at first position.n");
}
display();
}
Insert Node At Any Position
void insert_between()
{
if(start==NULL)
{
printf("List is empty. Create as the first node.n");
create();
}
else
{
int iPosition,iCount,iLoop,iData;
printf("Enter the position where you want to insert: ");
scanf("%d",&iPosition);
iCount=count();
if(iPosition>iCount)
{
printf("There are %d elements.n",iCount);
}
else
{
NODE *temp,*traverse;
traverse=start;
printf("Enter an integer value: ");
scanf("%d",&iData);
temp = (NODE *)malloc(sizeof(NODE));
temp->prev=NULL;
temp->info=iData;
temp->next=NULL;
for(iLoop=0;iLoop<iPosition-2;iLoop++)
{
traverse=traverse->next;
}
temp->prev=traverse;
temp->next=traverse->next;
traverse->next->prev=temp;
traverse->next=temp;
printf("Node inserted at position %d.n",iPosition);
}
}
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();
printf("Node inserted at the end.n");
}
display();
}
Counting Of Nodes
int count()
{
int iCount=0;
NODE *traverse;
traverse=start;
while(traverse!=NULL)
{
traverse=traverse->next;
iCount++;
}
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 The First Node
void delete_first()
{
NODE *delete_node;
if(start==NULL)
{
printf("There are no nodes to be deleted. The list is
empty.n");
}
else
{
delete_node=start;
start=start->next;
free(delete_node);
printf("The first node is deleted.n");
}
display();
}
Delete The Last Node
void delete_end()
{
NODE *delete_node, *traverse;
if(start==NULL)
{
printf("There are no nodes to be deleted. The list is
empty.n");
}
else
{
traverse=start;
while(traverse->next->next!=NULL)
{
traverse=traverse->next;
}
delete_node=traverse->next;
traverse->next=NULL;
free(delete_node);
printf("The last node is deleted.n");
}
display();
}
Delete Node At Any Position
void delete_position()
{
if(start==NULL)
{
printf("There are no nodes to be deleted. The list is empty.n");
}
else
{
NODE *traverse, *delete_node;
int iPosition, iLoop, iCount;
printf("Enter the position to be deleted: ");
scanf("%d",&iPosition);
iCount=count();
if(iPosition>iCount)
{
printf("There are %d elements.n",iCount);
}
else
{
traverse=start;
for(iLoop=0;iLoop<iPosition-2;iLoop++)
{
traverse=traverse->next;
}
delete_node=traverse->next;
delete_node->next->prev=traverse;
traverse->next=delete_node->next;
free(delete_node);
printf("Node deleted at position %d.n",iPosition);
}
}
display();
}
Sorting
void sort()
{
static NODE *traverse1;
traverse1=start;
NODE *traverse2;
int iOuter_Loop,iInner_Loop,iCount,iTemp;
iCount=count();
for(iOuter_Loop=0;iOuter_Loop<iCount-1;iOuter_Loop++)
{
traverse2=traverse1->next;
for(iInner_Loop=iOuter_Loop+1;iInner_Loop<iCount;iInner_Loop++)
{
if(traverse1->info>traverse2->info)
{
iTemp=traverse1->info;
traverse1->info=traverse2->info;
traverse2->info=iTemp;
}
traverse2=traverse2->next;
}
traverse1=traverse1->next;
}
printf("Nodes sortedn");
display();
}
Reversal Of The List
void reverse()
{
NODE *previous, *current;
previous=start;
current=previous->next;
previous->prev=current;
previous->next=NULL;
while(current!=NULL)
{
current->prev=current->next;
current->next=previous;
previous=current;
current=current->prev;
}
start=previous;
printf("Nodes reversedn");
display();
}
Searching
void find()
{
int iData;
NODE *traverse;
printf("Enter a number to be searched: ");
scanf("%d",&iData);
traverse=start;
while(traverse!=NULL)
{
if(traverse->info==iData)
{
printf("Element found.");
return;
}
else
{
traverse=traverse->next;
}
}
printf("Element not found.");
}
Presented By:
Sayantan Sur
Thank You
Ad

More Related Content

What's hot (20)

week-16x
week-16xweek-16x
week-16x
KITE www.kitecolleges.com
 
Avl tree
Avl treeAvl tree
Avl tree
loyola ICAM college of engineering and technology
 
Function basics
Function basicsFunction basics
Function basics
mohamed sikander
 
C++ programs
C++ programsC++ programs
C++ programs
Mukund Gandrakota
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
Implementing string
Implementing stringImplementing string
Implementing string
mohamed sikander
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
mohamed sikander
 
Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
Harjinder Singh
 
week-18x
week-18xweek-18x
week-18x
KITE www.kitecolleges.com
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
week-17x
week-17xweek-17x
week-17x
KITE www.kitecolleges.com
 
งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์
น้ำตาล มาแล้วจ้า
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
Chhom Karath
 
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
vrgokila
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
Chhom Karath
 
C questions
C questionsC questions
C questions
mohamed sikander
 
Arrays
ArraysArrays
Arrays
mohamed sikander
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
vinay arora
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
C programming array & shorting
C  programming array & shortingC  programming array & shorting
C programming array & shorting
argusacademy
 

Viewers also liked (20)

Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
dchuynh
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Linked list
Linked listLinked list
Linked list
akshat360
 
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
student
 
Data structures1
Data structures1Data structures1
Data structures1
Parthipan Parthi
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
Dynamic data structures
Dynamic data structuresDynamic data structures
Dynamic data structures
9020303098
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
Roshan Chaudhary
 
Eventually-Consistent Data Structures
Eventually-Consistent Data StructuresEventually-Consistent Data Structures
Eventually-Consistent Data Structures
Sean Cribbs
 
Purely functional data structures demystified
Purely functional data structures demystifiedPurely functional data structures demystified
Purely functional data structures demystified
Mohit Thatte
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Doubly Link List
Doubly Link ListDoubly Link List
Doubly Link List
Kashif Memon
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6
Teksify
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
iCreateWorld
 
10 generics a-4_in_1
10 generics a-4_in_110 generics a-4_in_1
10 generics a-4_in_1
arasforever
 
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
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
Fahd Allebdi
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
dchuynh
 
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
student
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
Dynamic data structures
Dynamic data structuresDynamic data structures
Dynamic data structures
9020303098
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
Roshan Chaudhary
 
Eventually-Consistent Data Structures
Eventually-Consistent Data StructuresEventually-Consistent Data Structures
Eventually-Consistent Data Structures
Sean Cribbs
 
Purely functional data structures demystified
Purely functional data structures demystifiedPurely functional data structures demystified
Purely functional data structures demystified
Mohit Thatte
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6
Teksify
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
iCreateWorld
 
10 generics a-4_in_1
10 generics a-4_in_110 generics a-4_in_1
10 generics a-4_in_1
arasforever
 
Ad

Similar to Double linked list (20)

C basics
C basicsC basics
C basics
MSc CST
 
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
Lakshmi Sarvani Videla
 
Cpds lab
Cpds labCpds lab
Cpds lab
praveennallavelly08
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
Kandarp Tiwari
 
Array menu
Array menuArray menu
Array menu
Sayantan Sur
 
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
9096308941
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
 
week-21x
week-21xweek-21x
week-21x
KITE www.kitecolleges.com
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
MeghaKulkarni27
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
mustkeem khan
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
mustkeem khan
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Pnno
PnnoPnno
Pnno
shristichaudhary4
 
C program
C programC program
C program
Komal Singh
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
Ad

More from Sayantan Sur (9)

Image Encryption and Compression
Image Encryption and Compression Image Encryption and Compression
Image Encryption and Compression
Sayantan Sur
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
Sayantan Sur
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
Sayantan Sur
 
Decision Support System(DSS)
Decision Support System(DSS)Decision Support System(DSS)
Decision Support System(DSS)
Sayantan Sur
 
Network Security
Network SecurityNetwork Security
Network Security
Sayantan Sur
 
Visual Studio IDE
Visual Studio IDEVisual Studio IDE
Visual Studio IDE
Sayantan Sur
 
Ethical Hacking
Ethical HackingEthical Hacking
Ethical Hacking
Sayantan Sur
 
Phising
PhisingPhising
Phising
Sayantan Sur
 
International Terrorism
International Terrorism International Terrorism
International Terrorism
Sayantan Sur
 
Image Encryption and Compression
Image Encryption and Compression Image Encryption and Compression
Image Encryption and Compression
Sayantan Sur
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
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
 

Recently uploaded (20)

Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 

Double linked list

  • 1. DOUBLE 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 { struct node *prev; int info; struct node *next; }; 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; temp=(NODE*)malloc(sizeof(NODE)); temp->prev=NULL; temp->next=NULL; printf("Enter an integer value: "); scanf("%d",&iData); temp->info=iData; if(start==NULL) { start=temp; } else { traverse=start; while(traverse->next!=NULL) { traverse=traverse->next; } traverse->next=temp; temp->prev=traverse; } }
  • 5. Display Of The Nodes void display() { NODE *traverse; if(start==NULL) { printf("There are no nodes to be displayed. The list is empty.n"); } else { traverse=start; printf("The linked list is: "); while(traverse!=NULL) { printf("%d ",traverse->info); traverse=traverse->next; } } }
  • 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. Insert Node At The First Position void insert_first() { NODE *temp; if(start==NULL) { printf("List is empty. Create as the first node.n"); create(); } else { int iData; temp=(NODE *)malloc(sizeof(NODE)); temp->prev=NULL; temp->next=NULL; printf("Enter an integer value: "); scanf("%d",&iData); temp->info=iData; start->prev=temp; temp->next=start; start=temp; printf("Node inserted at first position.n"); } display(); }
  • 8. Insert Node At Any Position void insert_between() { if(start==NULL) { printf("List is empty. Create as the first node.n"); create(); } else { int iPosition,iCount,iLoop,iData; printf("Enter the position where you want to insert: "); scanf("%d",&iPosition); iCount=count(); if(iPosition>iCount) { printf("There are %d elements.n",iCount); } else { NODE *temp,*traverse; traverse=start; printf("Enter an integer value: "); scanf("%d",&iData); temp = (NODE *)malloc(sizeof(NODE)); temp->prev=NULL; temp->info=iData; temp->next=NULL; for(iLoop=0;iLoop<iPosition-2;iLoop++) { traverse=traverse->next; } temp->prev=traverse; temp->next=traverse->next; traverse->next->prev=temp; traverse->next=temp; printf("Node inserted at position %d.n",iPosition); } } 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(); printf("Node inserted at the end.n"); } display(); }
  • 10. Counting Of Nodes int count() { int iCount=0; NODE *traverse; traverse=start; while(traverse!=NULL) { traverse=traverse->next; iCount++; } 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 The First Node void delete_first() { NODE *delete_node; if(start==NULL) { printf("There are no nodes to be deleted. The list is empty.n"); } else { delete_node=start; start=start->next; free(delete_node); printf("The first node is deleted.n"); } display(); }
  • 13. Delete The Last Node void delete_end() { NODE *delete_node, *traverse; if(start==NULL) { printf("There are no nodes to be deleted. The list is empty.n"); } else { traverse=start; while(traverse->next->next!=NULL) { traverse=traverse->next; } delete_node=traverse->next; traverse->next=NULL; free(delete_node); printf("The last node is deleted.n"); } display(); }
  • 14. Delete Node At Any Position void delete_position() { if(start==NULL) { printf("There are no nodes to be deleted. The list is empty.n"); } else { NODE *traverse, *delete_node; int iPosition, iLoop, iCount; printf("Enter the position to be deleted: "); scanf("%d",&iPosition); iCount=count(); if(iPosition>iCount) { printf("There are %d elements.n",iCount); } else { traverse=start; for(iLoop=0;iLoop<iPosition-2;iLoop++) { traverse=traverse->next; } delete_node=traverse->next; delete_node->next->prev=traverse; traverse->next=delete_node->next; free(delete_node); printf("Node deleted at position %d.n",iPosition); } } display(); }
  • 15. Sorting void sort() { static NODE *traverse1; traverse1=start; NODE *traverse2; int iOuter_Loop,iInner_Loop,iCount,iTemp; iCount=count(); for(iOuter_Loop=0;iOuter_Loop<iCount-1;iOuter_Loop++) { traverse2=traverse1->next; for(iInner_Loop=iOuter_Loop+1;iInner_Loop<iCount;iInner_Loop++) { if(traverse1->info>traverse2->info) { iTemp=traverse1->info; traverse1->info=traverse2->info; traverse2->info=iTemp; } traverse2=traverse2->next; } traverse1=traverse1->next; } printf("Nodes sortedn"); display(); }
  • 16. Reversal Of The List void reverse() { NODE *previous, *current; previous=start; current=previous->next; previous->prev=current; previous->next=NULL; while(current!=NULL) { current->prev=current->next; current->next=previous; previous=current; current=current->prev; } start=previous; printf("Nodes reversedn"); display(); }
  • 17. Searching void find() { int iData; NODE *traverse; printf("Enter a number to be searched: "); scanf("%d",&iData); traverse=start; while(traverse!=NULL) { if(traverse->info==iData) { printf("Element found."); return; } else { traverse=traverse->next; } } printf("Element not found."); }