在线等待,急!两个单链表有序合并,为什么输不出c链
#include "iostream.h"
typedef struct student
{
long number;
float score;
student * next;
}student, *linklist;
void crea(linklist & head,int n)
{
student * ps,* pEnd;
int i;
if((head=new student)==NULL)
{ cout<<"ERROR!"<<endl; return; }
cout<<"enter students' number and score!"<<endl;
cin>>head->number>>head->score;
pEnd=head;
for(i=1;i<n;i++)
{
if((ps=new student)==NULL)
{ cout<<"ERROR!"<<endl; return; }
cout<<"enter students' number and score!"<<endl;
cin>>ps->number>>ps->score;
pEnd->next=ps;
pEnd=ps;
}
pEnd->next=NULL;
}
void showlist(linklist & l,int num)
{
int i;
for(i=0;i<num;i++)
{
cout<<" number : "<<l->number<<" "<<" score : "<<l->score<<endl;
l=l->next;
}
}
void unionlist(linklist & la,linklist & lb,linklist & lc)
{
student *pa,*pb,*q;
pa=la;
pb=lb;
lc=la;
q=lc;
while(pa&&pb)
{
if(pa->number<=pb->number)
{ q->next=pa;
pa=pa->next;
q=pa; }
else
{ q->next=pb;
pb=pb->next;
q=pb; }
}
q=pa?pa:pb;
}
void main()
{
int numa,numb;
linklist A,B,C;
cout<<"input total students in class A!"<<endl;
cin>>numa;
crea(A,numa);
cout<<" class A"<<endl;
cout<<endl;
showlist(A,numa);
cout<<"input total students in class B!"<<endl;
cin>>numb;
crea(B,numb);
cout<<" class B"<<endl;
cout<<endl;
showlist(B,numb);
unionlist(A,B,C);
showlist(C,numa+numb);
}