新人求高手帮忙看下什么问题。
我打算编一个链表将前两个链表的数字从小到大串起来,程序验证是没错的,但就是运行不了。一运行就跳出错误然后自动退出。求高手指点,谢谢!程序代码:
#include "stdio.h" #include "stdlib.h" typedef struct node { char data; struct node *next; }node; int m=sizeof(node); typedef struct list { node *head,*tail; int ten; }list; list *la,*lb,*lc; node *pa,*pb,*pc; void buildla (list &la) { la.head=(node *)malloc(m); pa=la.head->next; int i; printf("请依次输入la的十个数字:"); for (i=0;i<10;i++) { scanf("%d",pa->data); pa=pa->next; } scanf ("%d",pa->data); pa->next=NULL; } void buildlb (list &lb) { lb.head=(node *)malloc(m); pb=lb.head->next; int i; printf("请依次输入la的十个数字:"); for (i=0;i<10;i++) { scanf("%d",pb->data); pb=pb->next; } scanf ("%d",pb->data); pb->next=NULL; } void main (list &la,list &lb, list &lc) { buildla (la); buildlb (lb); lc.head=(node *)malloc(m); pa=la.head->next; pb=lb.head->next; lc.head=pc=la.head->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; } } pc->next=pa?pa:pb; pc=lc.head->next; while (pc) { printf("%3d",pc->data); pc=pc->next; } }