C语言将两个递增有序单链表归并为一个降序的单链表，求大侠帮忙看看

#include
#include
#define N 8
typedef struct list
{ char c;
struct list *next;
} SLIST;
SLIST *creat(char *a)
{ SLIST *h,*p,*q; int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i { q=(SLIST *)malloc(sizeof(SLIST));
q->c=a[i]; p->next=q; p=q;
}
p->next=0;
return h;
}
void output(SLIST *h)
{ SLIST *p;
p=h->next;
if (p==NULL) printf("\nThe list is NULL!\n");
else
while(p->c!=0)
{ printf("->%c",p->c); p=p->next; }
printf("->End\n");
}
}
SLIST *sub(SLIST *a,SLIST *b)
{

SLIST *pa,*pb,*r;

pa=a;

pb=b;

r=NULL; //r为新链表头

while(pa->c!=0&&pb->c!=0)

{

if(pa->c< pb->c)
{

a=a->next;
pa->next=r;
r=pa;
pa=a;

``````     }
else
{
b=b->next;
pb->next=r;
r=pb;
pb=b;
}
}

while(pa!=NULL)//如果是表1未完，它的剩余结点倒序插入。
{      a=a->next;
pa->next=r;
r=pa;
pa=a;
}
while(pb!=NULL)
{
b=b->next;
pb->next=r;
r=pb;
pb=b;
}
r=r->next;
return(r);
``````

}

void main()
char a[N]="abcdefg";
char b[N]="ABCDEFG";
printf("\nThe first list before merging:\n");
printf("\nThe second list before merging:\n");
printf("\nThe list after merging:\n");
}
/

1.程序运行结果为：
The first list before merging:

The second list before merging:

The list after merging:

====C语言将两个递增有序单链表归并为一个降序的单链表，求大侠帮忙看看 程序运行时最后报错，为什么呢？
*/

1个回答