各位编程爱好者,我本人无意中发现解决方法;下面的修改后的程序:
/*
2.26
*/
#include <stdio.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 100
#define NULL 0
typedef struct LNode {
int data;
struct LNode *next;
}*LinkList;
LinkList creat(LinkList head)
{
LinkList l, q, p;
int ch;
l = (LinkList)malloc(sizeof(LinkList));
l->data = 0;
l->next = NULL;
q = l;
p = l;
printf("Input the Incremental s:\n");
scanf("%d",&ch);
//printf("%d\n",ch);
while (ch != 0)
{
p = (LinkList)malloc(sizeof(LinkList));
p->data = ch;
p->next = NULL;
q->next = p;
q = p;
scanf("%d",&ch);
//printf("%d\n",ch);
}
q = l;
return q;//It is OK!
}
LinkList Mergelist(LinkList A,LinkList B)
{
LinkList pa, pb, pc;
LinkList l, s;
l = (LinkList)malloc(sizeof(LinkList));
l->data = 0;
l->next = NULL;
pa = A->next;
pb = B->next;
pc = l;
while (pa && pb)
{
if (pa->data != pb->data)
{
pa = pa->next;
pb = pb->next;
}
else
{
s = (LinkList)malloc(sizeof(LinkList));
s->data = pa->data;
pc->next = s;
pc = s;
pa = pa->next;
pb = pb->next;
}
}
pc = l;
return pc;
}//
Mergelist
void Print(LinkList p)
{
if (p != NULL)
{
do {
printf(" %d",p->data);
p = p->next;
}
while (p != NULL);
}
else
printf("Wrong!\n");
printf("\n\n");
free(p);
}
int main()
{
LinkList a, b, c;
LinkList l;
l = (LinkList)malloc(sizeof(LinkList));
l->data = 0;
l->next = NULL;
a = l;
b = l;
c = l;
a = creat(a);
b = creat(b);
c = Mergelist(a, b);
printf("Output the Descending series:\n");
c = c->next;
Print(c);
return 0;
}