我的有序链表合并问题哪错了???请帮忙!!!
程序代码:
#include<stdio.h> #include<malloc.h> struct linklist { int data; struct linklist *next; }; #define LEN sizeof(struct linklist) struct linklist*creat(); struct linklist*merg(struct linklist*la,struct linklist*lb,struct linklist*lc); void print(struct linklist*head); void main() { printf("欢迎进入有序链表合并系统\n"); struct linklist*LA,*LB,*LC; printf("请输入链表1:\n"); LA=creat(); printf("请输入链表2:\n"); LB=creat(); merg(LA,LB,LC); print(LC); } struct linklist*creat() { int n; struct linklist*l; struct linklist*p1,*p2; n=0; p1=p2=(struct linklist*)malloc(LEN); scanf("%d",&p1->data); l=NULL; while(p1->data!=0) { n=n+1; if(n==1) l=p1; else p2->next=p1; p2=p1; p1=(struct linklist*)malloc(LEN); scanf("%d",&p1->data); } p2->next=NULL; return(l); } struct linklist*merg(struct linklist*la,struct linklist*lb,struct linklist*lc) { struct linklist*pa,*pb,*pc; pa=la; pb=lb; if(pa->data<=pb->data) { lc=pc=pa; pa=pa->next; } else {lc=pc=pb; pb=pb->next; } while(pa&&pb) { if(pa->data<=pb->data) { pc->next=pa; pc=pa; pa=pa->next; } else { pc->next=pb; pc=pb; pb=pb->next; } if(pa) pc->next=pa; else pc->next=pb; return(lc); } } void print(struct linklist*l) { struct linklist*p; p=l; do{ printf("%d",p->data); p=p->next; }while(p); }跳入黑屏后,输入两个链表后就直接停止运行,这是为什么???