the lists are merged. but the first term of the second list is missing in every output.
Merge sorted linked list-missing term
There is a slight error in your buildlist function, Use this :
void buildlist(node*&head,int n){
int data;
while(n>0)
{
cin>>data;
insertattail(head,data);
nā;
}
}