i make twwo single linkedlist,,
but i didn't know how i can merge those lists ;;
#include <iostream.h>
class linklist
{ private:
struct node
{
int data;
node *link;
} *p;
public:
linklist();
void append( int num );
void appendd(int size);
void display();
};
linklist::linklist()
{
p=NULL;
}
void linklist::append(int num)
{
node *q,*t;
if( p == NULL )
{
p = new node;
p->data = num;
p->link = NULL;
cin>>p->data;
}
else
{
q = p;
while( q->link != NULL )
q = q->link;
t = new node;
t->data = num;
t->link = NULL;
q->link = t;
cin>>t->data;
}
}
void linklist::appendd(int size)
{
node *z,*m;
if( p == NULL )
{
p = new node;
p->data = size;
p->link = NULL;
cin>>p->data;
}
else
{
z = p;
while( z->link != NULL )
z = z->link;
m= new node;
m->data = size;
m->link = NULL;
z->link = m;
cin>>m->data;
}
}
void linklist::display(){
cout<<" Elements are ";
while (p!=NULL){
cout<<p->data<<" ";
p=p->link;
}}
int main()
{int num,size;
linklist opj;
cout<<"No. of elements = ";
cin>>num;
cout<<"The nodes are #";
for (int i=0;i<num;i++)
opj.append(num );
opj.display();
cout<<"\nENTER";
cin>>size;
for ( i=0;i<size;i++)
opj.appendd(size);
opj.display();
return 0;
}