/*PROGRAM TO INSERT AN ELEMENT AT THE END OF DOUBLY LINKED LIST*/
#include<conio.h>
#include<iostream.h>
struct node
{
int data;
struct node *flink,*plink;
};
void main()
{
struct node *start=NULL,*ptr,*temp,*ptr1;
int num;
char ch;
clrscr();
cout<<“Inserting elements in the list: “<<endl;
do
{
temp=new node;
cout<<“Enter the element: “;
cin>>num;
temp->data=num;
if(start==NULL)
{
start=temp;
start->plink=NULL;
start->flink=NULL;
}
else
{ ptr=start;
while(ptr->flink!=NULL)
{
ptr=ptr->flink;
}
temp->flink=ptr->flink;
temp->plink=ptr;
ptr->flink=temp;
}
cout<<“Do you want to continue?? “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
cout<<“Elements in the forward direction are: “<<endl;
for(ptr=start;ptr->flink!=NULL;ptr=ptr->flink)
{
cout<<ptr->data<<“\t”;
}
cout<<ptr->data<<endl;
cout<<“Elements in the backward direction are: “<<endl;
for(ptr1=ptr;ptr1!=NULL;ptr1=ptr1->plink)
{
cout<<ptr1->data<<“\t”;
}
getch();
}