SlideShare a Scribd company logo
1 of 9
Download to read offline
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 (20)

Function
FunctionFunction
Function
 
Expression trees
Expression treesExpression trees
Expression trees
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Singly & Circular Linked list
Singly & Circular Linked listSingly & Circular Linked list
Singly & Circular Linked list
 
Array operations
Array operationsArray operations
Array operations
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Trees.pptx
Trees.pptxTrees.pptx
Trees.pptx
 
C++ file
C++ fileC++ file
C++ file
 
Tree Traversal
Tree TraversalTree Traversal
Tree Traversal
 
Hashing data
Hashing dataHashing data
Hashing data
 
Quick sort algorithm using slide presentation , Learn selection sort example ...
Quick sort algorithm using slide presentation , Learn selection sort example ...Quick sort algorithm using slide presentation , Learn selection sort example ...
Quick sort algorithm using slide presentation , Learn selection sort example ...
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
 
Pointers - DataStructures
Pointers - DataStructuresPointers - DataStructures
Pointers - DataStructures
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Linked list
Linked listLinked list
Linked list
 
Searching in Arrays
Searching in ArraysSearching in Arrays
Searching in Arrays
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 

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 LISTEr. Ganesh Ram Suwal
 
-- 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.docxAdamq0DJonese
 
Singly linked list.pptx
Singly linked list.pptxSingly linked list.pptx
Singly linked list.pptxSanthiya S
 
Php radomize
Php radomizePhp radomize
Php radomizedo_aki
 
C++ adt c++ implementations
C++   adt c++ implementationsC++   adt c++ implementations
C++ adt c++ implementationsRex Mwamba
 
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 .docxgordienaysmythe
 
__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.docxodiliagilby
 
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.pdfamitbagga0808
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
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 REDDYMalikireddy Bramhananda Reddy
 
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 {.docxLeonardN9WWelchw
 

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

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 

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