Wednesday 16 January 2013

Double Linked list with double data element

//double link list with double data

#include<conio.h>
#include<iostream.h>
struct node
{
struct node *plink;
int data1;
int data2;
struct node *flink;
};
void main()
{
clrscr();
 int i,n,d1,d2;
struct node *temp,*start=NULL;


temp=new node;
temp->plink=NULL;
temp->data1=100;
temp->data2=200;
temp->flink=NULL;
start=temp;
cout<<"----------------------------------------"<<endl;
cout<<"How Many element do you want to Insert |"<<endl;
cout<<"----------------------------------------"<<endl;
cin>>n;
    for(i=1;i<=n;i++)
    {
        cout<<"Enter data 1st in node" <<endl;
        cin>>d1;
        cout<<"Enter data 2nd in node" <<endl;
        cin>>d2;
        temp=new node;
        temp->plink=NULL;
        temp->data1=d1;
        temp->data2=d2;
        temp->flink=start;
        start->plink=temp;
        start=temp;
    }

                 cout<<"-----------"<<endl;
                cout<<"Data in link|"<<endl;
                cout<<"------------"<<endl;
        for(temp=start;temp!=NULL;temp=temp->flink)
                    {

                                cout<<"---------"<<endl;
                                cout<<"!"<<temp->data1<<"!"<<temp->data2<<"!"<<endl;
                                cout<<"---------"<<endl;
                    }



}

No comments:

Post a Comment