PROGRAM INSERT ELEMENT IN THE BEGINING OF DOUBLY LINKED LIST

/*PROGRAM TO INSERT AN ELEMENT IN THE BEGINING 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
{
temp->flink=start;
temp->plink=NULL;
start->plink=temp;
start=temp;
}
cout<<“Do you want to continue?? “;
cin>>ch;
}while(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();
}