Hi
I've tried the code below to merge 2 linked list which f1 and f2 are the first nodes in the initial lists and the "first" is the first node in the result list.
But it doesn't work!
node *merge(node *first,node *f1, node *f2,int n1,int n2){
int n=n1+n2;
while(n-- > 0){
if(n1-- > 0)first=insert(first,f1->info);
if(n2-- > 0)first=insert(first,f2->info);
}
return first;
}
Which insert is the following function that construc a list:
node *insert(node *first, int x){
if(first==NULL){
first=new node;
first->info=x;
first->next=NULL;
}
else{
node *Temp=first;
while(Temp->next!=NULL)
Temp=Temp->next;
Temp->next=new node;
Temp=Temp->next;
Temp->info=x;
Temp->next=NULL;
}
return first;
}
Looking forward to see your advice!:)