In computer science, a doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes.
program:
// Dobly Link List DELETE First
#include<iostream>
#include<conio.h>
using namespace std;
struct node
{
int info;
node *plink,*flink;
}*head=NULL,*tail=NULL,*nptr,*ptr;
void insert()
{
nptr=new node;
int item;
cout<<"Enter the Value";
cin>>item;
nptr->info=item;
if (head==NULL)
{
head=nptr;
tail=nptr;
nptr->plink=NULL;
nptr->flink=NULL;
}
else
{
ptr=head;
nptr->flink=ptr;
nptr->plink=NULL;
ptr->plink=nptr;
head=nptr;
}
}
void deletef()
{
ptr=head;
head=ptr->flink;
head->plink=NULL;
}
void traverse()
{
ptr=head;
while(ptr!=NULL)
{
cout<<ptr->info<<endl;
ptr=ptr->flink;
}
}
int main()
{
int n,i;
cout<<"Enter the no of element you want to enter";
cin>>n;
for(i=1;i<=n;i++)
{
insert();
}
deletef();
traverse();
}
program:
// Dobly Link List DELETE First
#include<iostream>
#include<conio.h>
using namespace std;
struct node
{
int info;
node *plink,*flink;
}*head=NULL,*tail=NULL,*nptr,*ptr;
void insert()
{
nptr=new node;
int item;
cout<<"Enter the Value";
cin>>item;
nptr->info=item;
if (head==NULL)
{
head=nptr;
tail=nptr;
nptr->plink=NULL;
nptr->flink=NULL;
}
else
{
ptr=head;
nptr->flink=ptr;
nptr->plink=NULL;
ptr->plink=nptr;
head=nptr;
}
}
void deletef()
{
ptr=head;
head=ptr->flink;
head->plink=NULL;
}
void traverse()
{
ptr=head;
while(ptr!=NULL)
{
cout<<ptr->info<<endl;
ptr=ptr->flink;
}
}
int main()
{
int n,i;
cout<<"Enter the no of element you want to enter";
cin>>n;
for(i=1;i<=n;i++)
{
insert();
}
deletef();
traverse();
}
double link list
Reviewed by Shobhit Goel
on
November 07, 2015
Rating:
No comments:
Post a Comment