After explaining singly linked list , circular linked list so now I explain you a doubly linked list .In singly linked list,each node has ...
After explaining singly linked list,circular linked list so now I explain you a doubly linked list.In singly linked list,each node has two parts i.e. info part/operation part and next pointer but in doubly linked list each node has 3 parts i.e. info,next pointer and pre part(so this is the main advantage of doubly linked list as compared to singly linked list).It is used in c ++,java,c# etc.
Example/implementation or Algorithm/program of Doubly linked list:-
#include<iostream.h>
#include<conio.h>
#include null 0
#include<stdio.h>
#include<stdlib.h>
void main()
{
struct link
{
int info;
struct link* next*pre;
}*start,*node*last;
char ch;
clrscr();
start=null;
node=null;
do
{
if(node==null)
{
node=new link;
start=node;
node->pre=null;
}
else
{
node->next=node link;
node->next->pre=null;
node=node->next;
}
cout<<"enter information for node";
cin>>node->info;
Cout<<"want to continue";
flushall();
cin>>ch;
}while(ch!='n');
last=node;
node->next=null;
node=start;
cout<<"List=";
while(node)
{
cout<<node->info;
node=node->next;
}
node=last;
cout<<"Reverse list/reversing a list";
while (node)
{
cout<<node->info;
node=node->pre;
getch();
}
That's all about Doubly Linked List in data structure.
#include<iostream.h>
#include<conio.h>
#include null 0
#include<stdio.h>
#include<stdlib.h>
void main()
{
struct link
{
int info;
struct link* next*pre;
}*start,*node*last;
char ch;
clrscr();
start=null;
node=null;
do
{
if(node==null)
{
node=new link;
start=node;
node->pre=null;
}
else
{
node->next=node link;
node->next->pre=null;
node=node->next;
}
cout<<"enter information for node";
cin>>node->info;
Cout<<"want to continue";
flushall();
cin>>ch;
}while(ch!='n');
last=node;
node->next=null;
node=start;
cout<<"List=";
while(node)
{
cout<<node->info;
node=node->next;
}
node=last;
cout<<"Reverse list/reversing a list";
while (node)
{
cout<<node->info;
node=node->pre;
getch();
}
That's all about Doubly Linked List in data structure.
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.
COMMENTS