求大神帮忙看一下这个程序那有问题为啥输不出结果?
#include<stdio.h>#include<stdlib.h>
typedef struct stdent
{
int num;
struct stdent *next;
}tu;
tu *creat( int n)
{
tu *p1,*p2,*head;
int i=1;
p1=p2=head=(tu*)malloc(sizeof(tu));
while(i<=n)
{
p1=(tu*)malloc(sizeof(tu));
printf("请输入第%d个数据:",i);
scanf("%d",&p1->num);
p2->next=p1;
p2=p1;
i++;
}
p2->next=NULL;
return head;
}
tu *pai(tu *la,tu *lb)
{
tu *p1,*p2,*p3;
p1=la->next;
p2=lb->next;
la->next=NULL;
while(p1!=NULL&&p2!=NULL)
{
if(p1->num<p2->num)
{
p3=p1->next;
p1=la->next;
la->next=p1;
p1=p3;
}
else
{
p3=p2->next;
p2=la->next;
la->next=p2;
p2=p3;
}
}
while(p1!=NULL)
{
p3=p1->next;
p1=la->next;
la->next=p1;
p1=p3;
}
while(p2!=NULL)
{
p3=p2->next;
p2=la->next;
la->next=p2;
p2=p3;
}
return la;
}
void printlist(tu *h)
{
tu *p;
p=h->next;
while(p!=NULL)
{
printf("%d\n",p->num);
p=p->next;
}
}
main( )
{
tu *la,*lb,*head;
int n;
printf("请输入链表la的节点数");
scanf("%d",&n);
la=creat(n);
printlist(la);
printf("请输入链表lb的节点数");
scanf("%d",&n);
lb=creat(n);
printlist(lb);
printf("合并降序后的链表为\n");
head=pai(la,lb);
printlist(head);
}