SlideShare a Scribd company logo
Doubly Linear Linked List
/***** @author: Er. Ganesh Ram Suwal *****/
/* Doubly Linked List */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<process.h>
// Global variables
int data,position,i;
//Structure for Node
struct node
{
int info;
struct node *pnext,*pprev;
};
struct node *pthis, *pnew, *ptemp, *pfirst;
// Fubction Prototype
void nifb();
void nibxp();
void niaxp();
void nife();
void ndfb();
void ndfe();
void ndfsp();
void display();
void newNode()
{
pnew = (struct node*)malloc(sizeof(struct node));
printf("Data : ");
scanf("%d",&data);
pnew->info = data;
}
void invalidPosition()
{
printf("n****************************************************n");
printf(" Invalid Position! Try Again ");
printf("n****************************************************n");
}
// Counting the nodes of Linked List
int length()
{
int count = 0;
if(pfirst == NULL)
{
return 0;
}
else
{
pthis = pfirst;
count = 1;
while(pthis->pnext != NULL)
{
pthis = pthis->pnext;
Doubly Linear Linked List
count = count + 1;
}
return count;
}
}
// Main program function
void main()
{
clrscr();
int choice;
start:
printf("n********* Doubly Linked List *******************n");
printf("1: Node insertion from the beginingn");
printf("2: Node insertion from the endn");
printf("3: Node insertion before Xth positionn");
printf("4: Node insertion after Xth positionn");
printf("5: Node Delete from the begining n");
printf("6: Node Delete from the endn");
printf("7: Node delete from specified positionn");
printf("8: Displayn");
printf("9: Exitn");
printf("Enter your choice :");
scanf("%d",&choice);
switch(choice)
{
case 1:nifb();
break;
case 2:nife();
break;
case 3:nibxp();
break;
case 4:niaxp();
break;
case 5:ndfb();
break;
case 6:ndfe();
break;
case 7:ndfsp();
break;
case 8:display();
break;
case 9:exit(0);
break;
default: printf("Invalid Choice");
break;
}
goto start;
}
// Node Insertion from the begining
void nifb()
{
newNode();
pnew->pprev = NULL;
if(pfirst == NULL)
{
pnew->pnext = NULL;
pfirst = pnew;
Doubly Linear Linked List
}
else
{
pnew->pnext = pfirst;
pfirst = pnew;
}
}
//Node insertion before Xth position
void nibxp()
{
printf("position : ");
scanf("%d",&position);
if(position > length() || position < 1)
{
invalidPosition();
}
else if(position == 1)
{
nifb();
}
else
{
newNode();
if(pfirst == NULL)
{
pnew->pnext = NULL;
pnew->pprev = NULL;
pfirst = pnew;
}
else
{
pthis = pfirst;
for(i = 0;i<position-2;i++)
{
pthis = pthis->pnext;
}
ptemp = pthis->pnext;
pthis->pnext = pnew;
pnew->pnext = ptemp;
pnew->pprev = pthis;
}
}
}
//Node Insertion after Xth Position
void niaxp()
{
printf("position : ");
scanf("%d",&position);
if(position > length() || position < 1)
{
printf("n****************************************************n");
printf("Invalid Position! Try Again ");
printf("n****************************************************n");
}
else if(position == length())
{
nife();
Doubly Linear Linked List
}
else
{
newNode();
if(pfirst == NULL)
{
pnew->pnext = NULL;
pnew->pprev = NULL;
pfirst = pnew;
}
else
{
pthis = pfirst;
for(i = 0;i<position-1;i++)
{
pthis = pthis->pnext;
}
ptemp = pthis->pnext;
pthis->pnext = pnew;
pnew->pnext = ptemp;
pnew->pprev = pthis;
}
}
}
// Node Insertion from the end
void nife()
{
newNode();
pnew->pnext = NULL;
if(pfirst == NULL)
{
pnew->pprev = NULL;
pfirst = pnew;
}
else
{
pthis = pfirst;
while(pthis->pnext != NULL)
{
pthis = pthis->pnext;
}
pthis->pnext = pnew;
pnew->pprev = pthis;
}
}
//node delete from the begining
void ndfb()
{
if(pfirst == NULL)
{
printf("n==================================================n");
printf(" There is no node in the list");
printf("n==================================================n");
}
else
{
Doubly Linear Linked List
pthis = pfirst;
if(pfirst->pnext == NULL)
{
pfirst = NULL;
}
else
{
pfirst = pthis->pnext;
pfirst->pprev = NULL;
}
printf("n=================================================================n")
;
printf("The deleted element = %d",pthis->info);
printf("n=================================================================n")
;
free(pthis);
}
}
//node delete from the end
void ndfe()
{
if(pfirst == NULL)
{
printf("n==================================================n");
printf(" There is no node in the list");
printf("n==================================================n");
}
else
{
pthis = pfirst;
if(pfirst->pnext == NULL)
{
pfirst = NULL;
printf("n=================================================================n");
printf("The deleted element = %d",pthis->info);
printf("n=================================================================n");
free(pthis);
}
else
{
while(pthis->pnext->pnext != NULL)
{
pthis = pthis->pnext;
}
printf("n=================================================================n");
printf("The deleted node = %d",pthis->pnext->info);
printf("n=================================================================n");
free(pthis->pnext);
pthis->pnext = NULL;
}
}
}
Doubly Linear Linked List
//node delete from the specified position
void ndfsp()
{
if(pfirst == NULL)
{
printf("n==================================================n");
printf(" There is no node in the list");
printf("n==================================================n");
}
else
{
printf("Position : ");
scanf("%d",&position);
if(position > length() || position < 1)
{
invalidPosition();
}
else if(position == 1)
{
ndfb();
}
else if(position == length())
{
ndfe();
}
else
{
pthis = pfirst;
for(i=0;i<position-2;i++)
{
pthis=pthis->pnext;
}
ptemp = pthis->pnext->pnext;
printf("n=================================================================n");
printf("The deleted element = %d",pthis->pnext->info);
printf("n=================================================================n");
free(pthis->pnext);
pthis->pnext = ptemp;
pthis->pnext->pprev = pthis;
}
}
}
//Display function
void display()
{
int l;
l = length();
printf("n=================================================================n");
if(pfirst == NULL)
{
printf("There is no data in linked List");
}
else
{
printf("Node in DLL (Length=%d) : ",l);
Doubly Linear Linked List
pthis = pfirst;
printf("%d ",pthis->info);
while(pthis->pnext != NULL)
{
pthis = pthis->pnext;
printf("%d ",pthis->info);
}
}
printf("n=================================================================n");
}
OUTPUT
Doubly Linear Linked List
Doubly Linear Linked List

More Related Content

What's hot

Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Stack, Queue, Linked List.pptx
Stack, Queue, Linked List.pptxStack, Queue, Linked List.pptx
Stack, Queue, Linked List.pptx
Bharati Vidyapeeth COE, Navi Mumbai
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
minal kumar soni
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
Digvijay Singh Karakoti
 
What is Range Function? | Range in Python Explained | Edureka
What is Range Function? | Range in Python Explained | EdurekaWhat is Range Function? | Range in Python Explained | Edureka
What is Range Function? | Range in Python Explained | Edureka
Edureka!
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
sumitbardhan
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Trees.pptx
Trees.pptxTrees.pptx
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Afaq Mansoor Khan
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
Megha V
 
deque and it applications
deque and it applicationsdeque and it applications
deque and it applications
Sathasivam Rangasamy
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
C Pointers
C PointersC Pointers
C Pointers
omukhtar
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
ppd1961
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
Ashim Lamichhane
 

What's hot (20)

Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Stack, Queue, Linked List.pptx
Stack, Queue, Linked List.pptxStack, Queue, Linked List.pptx
Stack, Queue, Linked List.pptx
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
What is Range Function? | Range in Python Explained | Edureka
What is Range Function? | Range in Python Explained | EdurekaWhat is Range Function? | Range in Python Explained | Edureka
What is Range Function? | Range in Python Explained | Edureka
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Trees.pptx
Trees.pptxTrees.pptx
Trees.pptx
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Linked List
Linked ListLinked List
Linked List
 
Linked list
Linked listLinked list
Linked list
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
deque and it applications
deque and it applicationsdeque and it applications
deque and it applications
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
C Pointers
C PointersC Pointers
C Pointers
 
Stl Containers
Stl ContainersStl Containers
Stl Containers
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 

Similar to Doubly Linked List

STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LIST
Er. Ganesh Ram Suwal
 
week-16x
week-16xweek-16x
-- 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
 
Circular queue
Circular queueCircular queue
Circular queue
Er. Ganesh Ram Suwal
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
Santhiya S
 
Php radomize
Php radomizePhp radomize
Php radomize
do_aki
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementations
Rex Mwamba
 
Linear queue
Linear queueLinear queue
Linear queue
Er. Ganesh Ram Suwal
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Er. Ganesh Ram Suwal
 
Pointer
PointerPointer
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
odiliagilby
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
amitbagga0808
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
AkhilaaReddy
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
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
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
C program
C programC program
C program
Komal Singh
 
Data structures
Data structuresData structures
Data structures
gayatrigayu1
 
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxGIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
LeonardN9WWelchw
 

Similar to Doubly Linked List (20)

STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LIST
 
week-16x
week-16xweek-16x
week-16x
 
-- 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
 
Circular queue
Circular queueCircular queue
Circular queue
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptx
 
Php radomize
Php radomizePhp radomize
Php radomize
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementations
 
Linear queue
Linear queueLinear queue
Linear queue
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Pointer
PointerPointer
Pointer
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
__MACOSX._assign3assign3.DS_Store__MACOSXassign3._.D.docx
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
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
 
7 functions
7  functions7  functions
7 functions
 
C program
C programC program
C program
 
Data structures
Data structuresData structures
Data structures
 
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docxGIVEN CODE template -typename T- class DList { private- struct Node {.docx
GIVEN CODE template -typename T- class DList { private- struct Node {.docx
 

Recently uploaded

Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
AjmalKhan50578
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
Atif Razi
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 

Recently uploaded (20)

Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
Welding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdfWelding Metallurgy Ferrous Materials.pdf
Welding Metallurgy Ferrous Materials.pdf
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
Applications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdfApplications of artificial Intelligence in Mechanical Engineering.pdf
Applications of artificial Intelligence in Mechanical Engineering.pdf
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 

Doubly Linked List

  • 1. Doubly Linear Linked List /***** @author: Er. Ganesh Ram Suwal *****/ /* Doubly Linked List */ #include<stdio.h> #include<conio.h> #include<alloc.h> #include<process.h> // Global variables int data,position,i; //Structure for Node struct node { int info; struct node *pnext,*pprev; }; struct node *pthis, *pnew, *ptemp, *pfirst; // Fubction Prototype void nifb(); void nibxp(); void niaxp(); void nife(); void ndfb(); void ndfe(); void ndfsp(); void display(); void newNode() { pnew = (struct node*)malloc(sizeof(struct node)); printf("Data : "); scanf("%d",&data); pnew->info = data; } void invalidPosition() { printf("n****************************************************n"); printf(" Invalid Position! Try Again "); printf("n****************************************************n"); } // Counting the nodes of Linked List int length() { int count = 0; if(pfirst == NULL) { return 0; } else { pthis = pfirst; count = 1; while(pthis->pnext != NULL) { pthis = pthis->pnext;
  • 2. Doubly Linear Linked List count = count + 1; } return count; } } // Main program function void main() { clrscr(); int choice; start: printf("n********* Doubly Linked List *******************n"); printf("1: Node insertion from the beginingn"); printf("2: Node insertion from the endn"); printf("3: Node insertion before Xth positionn"); printf("4: Node insertion after Xth positionn"); printf("5: Node Delete from the begining n"); printf("6: Node Delete from the endn"); printf("7: Node delete from specified positionn"); printf("8: Displayn"); printf("9: Exitn"); printf("Enter your choice :"); scanf("%d",&choice); switch(choice) { case 1:nifb(); break; case 2:nife(); break; case 3:nibxp(); break; case 4:niaxp(); break; case 5:ndfb(); break; case 6:ndfe(); break; case 7:ndfsp(); break; case 8:display(); break; case 9:exit(0); break; default: printf("Invalid Choice"); break; } goto start; } // Node Insertion from the begining void nifb() { newNode(); pnew->pprev = NULL; if(pfirst == NULL) { pnew->pnext = NULL; pfirst = pnew;
  • 3. Doubly Linear Linked List } else { pnew->pnext = pfirst; pfirst = pnew; } } //Node insertion before Xth position void nibxp() { printf("position : "); scanf("%d",&position); if(position > length() || position < 1) { invalidPosition(); } else if(position == 1) { nifb(); } else { newNode(); if(pfirst == NULL) { pnew->pnext = NULL; pnew->pprev = NULL; pfirst = pnew; } else { pthis = pfirst; for(i = 0;i<position-2;i++) { pthis = pthis->pnext; } ptemp = pthis->pnext; pthis->pnext = pnew; pnew->pnext = ptemp; pnew->pprev = pthis; } } } //Node Insertion after Xth Position void niaxp() { printf("position : "); scanf("%d",&position); if(position > length() || position < 1) { printf("n****************************************************n"); printf("Invalid Position! Try Again "); printf("n****************************************************n"); } else if(position == length()) { nife();
  • 4. Doubly Linear Linked List } else { newNode(); if(pfirst == NULL) { pnew->pnext = NULL; pnew->pprev = NULL; pfirst = pnew; } else { pthis = pfirst; for(i = 0;i<position-1;i++) { pthis = pthis->pnext; } ptemp = pthis->pnext; pthis->pnext = pnew; pnew->pnext = ptemp; pnew->pprev = pthis; } } } // Node Insertion from the end void nife() { newNode(); pnew->pnext = NULL; if(pfirst == NULL) { pnew->pprev = NULL; pfirst = pnew; } else { pthis = pfirst; while(pthis->pnext != NULL) { pthis = pthis->pnext; } pthis->pnext = pnew; pnew->pprev = pthis; } } //node delete from the begining void ndfb() { if(pfirst == NULL) { printf("n==================================================n"); printf(" There is no node in the list"); printf("n==================================================n"); } else {
  • 5. Doubly Linear Linked List pthis = pfirst; if(pfirst->pnext == NULL) { pfirst = NULL; } else { pfirst = pthis->pnext; pfirst->pprev = NULL; } printf("n=================================================================n") ; printf("The deleted element = %d",pthis->info); printf("n=================================================================n") ; free(pthis); } } //node delete from the end void ndfe() { if(pfirst == NULL) { printf("n==================================================n"); printf(" There is no node in the list"); printf("n==================================================n"); } else { pthis = pfirst; if(pfirst->pnext == NULL) { pfirst = NULL; printf("n=================================================================n"); printf("The deleted element = %d",pthis->info); printf("n=================================================================n"); free(pthis); } else { while(pthis->pnext->pnext != NULL) { pthis = pthis->pnext; } printf("n=================================================================n"); printf("The deleted node = %d",pthis->pnext->info); printf("n=================================================================n"); free(pthis->pnext); pthis->pnext = NULL; } } }
  • 6. Doubly Linear Linked List //node delete from the specified position void ndfsp() { if(pfirst == NULL) { printf("n==================================================n"); printf(" There is no node in the list"); printf("n==================================================n"); } else { printf("Position : "); scanf("%d",&position); if(position > length() || position < 1) { invalidPosition(); } else if(position == 1) { ndfb(); } else if(position == length()) { ndfe(); } else { pthis = pfirst; for(i=0;i<position-2;i++) { pthis=pthis->pnext; } ptemp = pthis->pnext->pnext; printf("n=================================================================n"); printf("The deleted element = %d",pthis->pnext->info); printf("n=================================================================n"); free(pthis->pnext); pthis->pnext = ptemp; pthis->pnext->pprev = pthis; } } } //Display function void display() { int l; l = length(); printf("n=================================================================n"); if(pfirst == NULL) { printf("There is no data in linked List"); } else { printf("Node in DLL (Length=%d) : ",l);
  • 7. Doubly Linear Linked List pthis = pfirst; printf("%d ",pthis->info); while(pthis->pnext != NULL) { pthis = pthis->pnext; printf("%d ",pthis->info); } } printf("n=================================================================n"); } OUTPUT