SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Task: Define doubly linked .
code:
#include "stdafx.h"
#include<conio.h>
#include<iostream>
using namespace std;
class double_linklist
{
private:
struct node
{
int data;
node *prev;
node *next;
}*p;
int c;
public:
double_linklist()
{
p=NULL;
c=0;
}
bool isempty()
{
return(p==NULL);
}
void addatbeg(int num)
{
c++;
node *n;
n=new node;
n->data=num;
n->prev=NULL;
if(p==NULL)
{
n->next=NULL;
p=n;
}
else
{
n->next=p;
p->prev=n;
p=n;
}}
void addatend(int num)
{
c++;
node *n;
n=new node;
n->data=num;
n->next=NULL;
if(p==NULL)
{
n->prev=NULL;
p=n;
}
else
{
node *temp=p;
while(temp->next!=NULL)
{
temp=temp->next;
}
n->prev=temp;
temp->next=n;
}
}
void addafter(int num,int location)
{
if(isempty())
cout<<"Doubly link list is empty!!!"<<endl;
else if(c<location)
cout<<"Location not found!!!"<<endl;
else
{
c++;
node *n,*temp=p;
n=new node;
n->data=num;
while(1<location)
{
temp=temp->next;
location--;
}
temp->next->prev=n;
n->next=temp->next;
temp->next=n;
n->prev=temp;}}
void del(int num)
{
if(isempty())
cout<<"Doubly link list is empty!!!"<<endl;
else
{
node *temp=p;
while(temp!=NULL)
{
if(temp->data==num)
{
if(temp==p)
{
if(c==1)
p=NULL;
else
temp=p=p->next;
p->prev=NULL;
}
else if(temp->next==NULL)
{
temp->prev->next=NULL;
}
else
{
temp->next->prev=temp->prev;
temp->prev->next=temp->next;
}
c--;
}
temp=temp->next;}}}
void display()
{
if(p==NULL)
cout<<"Doubly link list is empty!!!"<<endl;
else
{
node *temp=p;
cout<<"Doubly link list elements are : "<<endl;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;}}}
void count()
{
cout<<"Total no of nodes is : "<<c<<endl;
}
~double_llist()
{
node *temp;
while(p!=NULL)
{
temp=p;
p=p->next;
delete temp;}}};
int _tmain(int argc, _TCHAR* argv[])
{
double_llist d_linkllist;
int c,num,location;
while(1)
{
cout<<"nDoubly linked list menu : "<<endl;
cout<<"n1.add at end of listn2.add at beginning of listn3.add after
specific in listn4.del from the list";
cout<<"n5.display the listn6.count total nodes of the
listn7.exit"<<endl;
cout<<"Enter your choice : ";
cin>>c;
switch(c)
{
case 1:
{
cout<<"Enter value : ";
cin>>num;
d_llist.addatend(num);
break;
}
case 2:
{
cout<<"Enter value : ";
cin>>num;
d_llist.addatbeg(num);
break;
}
case 3:
{
cout<<"Enter value : ";
cin>>num;
cout<<"Enter location after which you want to enter value : ";
cin>>location;
d_llist.addafter(num,location);
break;
}
case 4:
{
cout<<"Enter value : ";
cin>>num;
d_llist.del(num);
break;
}
case 5:
{
d_llist.display();
break;
}
case 6:
{
d_llist.count();
break;
}
case 7:
{
cout<<"You are exiting....."<<endl;
system("pause");
exit(0);
break;
}
default:
cout<<"Invalid choice!!!"<<endl;}}
system("pause");
return 0;}
Output:

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (19)

C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
VTU Network lab programs
VTU Network lab   programsVTU Network lab   programs
VTU Network lab programs
 
C++ file
C++ fileC++ file
C++ file
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
 
C++ Programming - 3rd Study
C++ Programming - 3rd StudyC++ Programming - 3rd Study
C++ Programming - 3rd Study
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
New presentation oop
New presentation oopNew presentation oop
New presentation oop
 
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++
 
timingExercise
timingExercisetimingExercise
timingExercise
 
C++ 4
C++ 4C++ 4
C++ 4
 
3 rd animation
3 rd animation3 rd animation
3 rd animation
 
Experement no 6
Experement no 6Experement no 6
Experement no 6
 
D vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoyaD vs OWKN Language at LLnagoya
D vs OWKN Language at LLnagoya
 
Coding with Vim
Coding with VimCoding with Vim
Coding with Vim
 
Code
CodeCode
Code
 

Andere mochten auch

Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500
ilsamaryum
 

Andere mochten auch (12)

Double checkedlockingjavasingletons
Double checkedlockingjavasingletonsDouble checkedlockingjavasingletons
Double checkedlockingjavasingletons
 
Programs of C++
Programs of C++Programs of C++
Programs of C++
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
Computer graphics programs in c++
Computer graphics programs in c++Computer graphics programs in c++
Computer graphics programs in c++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video Tutorial
 
Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500Write a program to print out all armstrong numbers between 1 and 500
Write a program to print out all armstrong numbers between 1 and 500
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Loops
LoopsLoops
Loops
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
C++ programs
C++ programsC++ programs
C++ programs
 

Ähnlich wie Doubly linklist

Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
Nasir Mehmood
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
jyothimuppasani1
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
ecomputernotes
 
Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docx
noreendchesterton753
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
ankitmobileshop235
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
aathiauto
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
anupambedcovers
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
acarolyn
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
fortmdu
 

Ähnlich wie Doubly linklist (20)

Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docx
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docx
 
Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docx
 
Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.Write a program that calculate the no of prime no,even and odd no.
Write a program that calculate the no of prime no,even and odd no.
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Bubble in link list
Bubble in link listBubble in link list
Bubble in link list
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
 
C++ manual Report Full
C++ manual Report FullC++ manual Report Full
C++ manual Report Full
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
 
Answer#include iostream using namespace std;struct NodeType.pdf
Answer#include iostream using namespace std;struct NodeType.pdfAnswer#include iostream using namespace std;struct NodeType.pdf
Answer#include iostream using namespace std;struct NodeType.pdf
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
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
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 

Kürzlich hochgeladen

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Kürzlich hochgeladen (20)

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 

Doubly linklist

  • 1. Task: Define doubly linked . code: #include "stdafx.h" #include<conio.h> #include<iostream> using namespace std; class double_linklist { private: struct node { int data; node *prev; node *next; }*p; int c; public: double_linklist() { p=NULL; c=0; } bool isempty() { return(p==NULL); } void addatbeg(int num) { c++; node *n; n=new node; n->data=num; n->prev=NULL; if(p==NULL) { n->next=NULL; p=n; } else { n->next=p; p->prev=n; p=n; }} void addatend(int num) { c++;
  • 2. node *n; n=new node; n->data=num; n->next=NULL; if(p==NULL) { n->prev=NULL; p=n; } else { node *temp=p; while(temp->next!=NULL) { temp=temp->next; } n->prev=temp; temp->next=n; } } void addafter(int num,int location) { if(isempty()) cout<<"Doubly link list is empty!!!"<<endl; else if(c<location) cout<<"Location not found!!!"<<endl; else { c++; node *n,*temp=p; n=new node; n->data=num; while(1<location) { temp=temp->next; location--; } temp->next->prev=n; n->next=temp->next; temp->next=n; n->prev=temp;}} void del(int num) { if(isempty()) cout<<"Doubly link list is empty!!!"<<endl; else { node *temp=p; while(temp!=NULL) {
  • 3. if(temp->data==num) { if(temp==p) { if(c==1) p=NULL; else temp=p=p->next; p->prev=NULL; } else if(temp->next==NULL) { temp->prev->next=NULL; } else { temp->next->prev=temp->prev; temp->prev->next=temp->next; } c--; } temp=temp->next;}}} void display() { if(p==NULL) cout<<"Doubly link list is empty!!!"<<endl; else { node *temp=p; cout<<"Doubly link list elements are : "<<endl; while(temp!=NULL) { cout<<temp->data<<" "; temp=temp->next;}}} void count() { cout<<"Total no of nodes is : "<<c<<endl; } ~double_llist() { node *temp; while(p!=NULL) { temp=p; p=p->next; delete temp;}}}; int _tmain(int argc, _TCHAR* argv[]) { double_llist d_linkllist; int c,num,location;
  • 4. while(1) { cout<<"nDoubly linked list menu : "<<endl; cout<<"n1.add at end of listn2.add at beginning of listn3.add after specific in listn4.del from the list"; cout<<"n5.display the listn6.count total nodes of the listn7.exit"<<endl; cout<<"Enter your choice : "; cin>>c; switch(c) { case 1: { cout<<"Enter value : "; cin>>num; d_llist.addatend(num); break; } case 2: { cout<<"Enter value : "; cin>>num; d_llist.addatbeg(num); break; } case 3: { cout<<"Enter value : "; cin>>num; cout<<"Enter location after which you want to enter value : "; cin>>location; d_llist.addafter(num,location); break; } case 4: { cout<<"Enter value : "; cin>>num; d_llist.del(num); break; } case 5: { d_llist.display(); break; } case 6: { d_llist.count(); break;
  • 5. } case 7: { cout<<"You are exiting....."<<endl; system("pause"); exit(0); break; } default: cout<<"Invalid choice!!!"<<endl;}} system("pause"); return 0;} Output: