double_link_list

#include"stdio.h"
#include"iostream.h"
#include"conio.h"
struct node
{
node *pre;
int data;
node *next;
};
class linklist
{
node *list,*nptr,*tptr;
public:
linklist()
{
list=NULL;
}
void newnode (int item);
void link(); //constructed
void showdata();
};
void linklist::newnode(int item)
{
nptr=new(node);
nptr->pre=NULL;
nptr->data=item;
nptr->next=NULL;
link();
}
void linklist::link()
{
if(list==NULL)
{
list=nptr;
tptr=nptr;
}
else
{
tptr->next=nptr;
nptr->pre=tptr;
tptr=nptr;
}
}
void linklist::showdata()
{
node *curptr;
curptr =list;
while(curptr->next !=NULL)
{
cout<<" " <data;
curptr=curptr->next;
}
cout<<" " <data;
//curptr=curptr-next
}


int main()
{
int n,d;


linklist mylist;

cout<<"how many node do you have?\t";
cin>>n;
cout<<"Enter data:"<<"\n";
for(int i=0;i {
cin>>d;
mylist.newnode(d);
}
cout<<"data in the list:";
mylist.showdata();


return 0;


}

No comments:

Post a Comment

Followers

About Me

Dhaka, Dhaka, Bangladesh
..