如何将两个链表合并?
#include "stdio.h"#include "stdlib.h"
struct student
{
long num;
float score;
struct student *next;
};
int main(int argc, char* argv[])
{
struct student a,b,c,d,e,f,*head1,*head2,*p,*q,*w;
a.num=99101;a.score=89;
b.num=99107;b.score=90;
c.num=99103;c.score=91;
head1=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
p=head1;
printf("第一个链表为:\n");
while(p!=NULL)
{
printf("%ld%5.1f\n",p->num,p->score);
p=p->next;
}
d.num=99103;d.score=92;
e.num=99104;e.score=93;
f.num=99105;f.score=94;
head2=&d;
d.next=&e;
e.next=&f;
f.next=NULL;
q=head2;
printf("第二个链表为:\n");
while(q!=NULL)
{
printf("%ld%5.1f\n",q->num,q->score);
q=q->next;
}//如何将第一个链表和第二个链表合并,并按num升序排序?
return 0;
}