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

PDF
Singly Linked List
PPT
Data Structures with C Linked List
PPTX
Linked List
PPTX
Linear data structure concepts
PPTX
Quick_sort1.pptx
PPT
PPTX
Doubly linked list (animated)
PPTX
Interpolation search
Singly Linked List
Data Structures with C Linked List
Linked List
Linear data structure concepts
Quick_sort1.pptx
Doubly linked list (animated)
Interpolation search

What's hot (20)

PPT
358 33 powerpoint-slides_8-linked-lists_chapter-8
PPTX
Linked list
PPT
PPT
Lec 17 heap data structure
PPT
Circular linked list
PPTX
Python - Data Structures
PPTX
Heap_Sort1.pptx
PPT
1.5 binary search tree
PPTX
Height balanced Tree
PPTX
Double Linked List (Algorithm)
PPTX
26 alternating series and conditional convergence x
PPTX
Linked List - Insertion & Deletion
PPT
Binary search tree in data structures
PPTX
Floating point representation
PPTX
Doubly circular linked list
PPTX
Stack_Data_Structure.pptx
PPTX
Tree_Definition.pptx
PPT
Arrays
358 33 powerpoint-slides_8-linked-lists_chapter-8
Linked list
Lec 17 heap data structure
Circular linked list
Python - Data Structures
Heap_Sort1.pptx
1.5 binary search tree
Height balanced Tree
Double Linked List (Algorithm)
26 alternating series and conditional convergence x
Linked List - Insertion & Deletion
Binary search tree in data structures
Floating point representation
Doubly circular linked list
Stack_Data_Structure.pptx
Tree_Definition.pptx
Arrays
Ad

Similar to Doubly Linked List (20)

DOC
C program to insert a node in doubly linked list
DOC
Final ds record
PPTX
Ll.pptx
PPTX
linked list.pptx
PDF
Program to insert in a sorted list #includestdio.h#include.pdf
PPTX
data structure3.pptx
DOCX
Shortened Linked List in C programming easy to learn for exam
PPTX
Implemention of Linked list concept in Data Structures
DOCX
What is Linked List in C.docx
PPTX
LINKED LIST.pptx
PDF
TutorialII_Updated____niceupdateprogram.pdf
PPTX
Dounly linked list
PDF
Data Structures in C++I am really new to C++, so links are really .pdf
PPTX
Double linked list.pptx
PDF
Linked list
PPTX
linkedlist.pptx
PDF
137 Lab-2.2.pdf
PDF
Lab-2.2 717822E504.pdf
DOCX
DS UNIT4_OTHER LIST STRUCTURES.docx
C program to insert a node in doubly linked list
Final ds record
Ll.pptx
linked list.pptx
Program to insert in a sorted list #includestdio.h#include.pdf
data structure3.pptx
Shortened Linked List in C programming easy to learn for exam
Implemention of Linked list concept in Data Structures
What is Linked List in C.docx
LINKED LIST.pptx
TutorialII_Updated____niceupdateprogram.pdf
Dounly linked list
Data Structures in C++I am really new to C++, so links are really .pdf
Double linked list.pptx
Linked list
linkedlist.pptx
137 Lab-2.2.pdf
Lab-2.2 717822E504.pdf
DS UNIT4_OTHER LIST STRUCTURES.docx
Ad

More from Er. Ganesh Ram Suwal (10)

PPT
UNIT 1: Problem Solving Using Computer
PDF
PDF
Tower of HANOI
PDF
STACK IMPLEMENTATION USING SINGLY LINKED LIST
PDF
Stack Data Structure
PDF
Circular queue
PDF
Linear queue
PDF
Proposal Writing
PPT
DSA chapter 1
PPT
Web Technology And Its Scope in NEPAL.pptx
UNIT 1: Problem Solving Using Computer
Tower of HANOI
STACK IMPLEMENTATION USING SINGLY LINKED LIST
Stack Data Structure
Circular queue
Linear queue
Proposal Writing
DSA chapter 1
Web Technology And Its Scope in NEPAL.pptx

Recently uploaded (20)

PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
web development for engineering and engineering
PPTX
Geodesy 1.pptx...............................................
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
additive manufacturing of ss316l using mig welding
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Well-logging-methods_new................
PPTX
Sustainable Sites - Green Building Construction
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
web development for engineering and engineering
Geodesy 1.pptx...............................................
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
additive manufacturing of ss316l using mig welding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Foundation to blockchain - A guide to Blockchain Tech
Internet of Things (IOT) - A guide to understanding
Well-logging-methods_new................
Sustainable Sites - Green Building Construction
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Operating System & Kernel Study Guide-1 - converted.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
R24 SURVEYING LAB MANUAL for civil enggi
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
CH1 Production IntroductoryConcepts.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx

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