#include "stdio.h"
#include "stdlib.h"
#define ElemType int
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
LNode *create(ElemType data[],int n)//创建
{
LNode *head, *p, *rear;
int k;
head = (LNode *)malloc(sizeof(LNode));
head->next = NULL;
rear = head;
for (k = 0; k < n; k++)
{
p = (LNode *)malloc(sizeof(LNode));
p->data = data[k];
p->next = NULL;
rear->next = p;
rear = p;
}
return head;
}
void display(LNode *head)//显示
{
LNode *p;
p = head->next;
while (p)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
LinkList Unionlist(LNode *LA, LNode *LB, LNode *LC//
{
LNode *pa, *pb, *pc;
pa = LA->next;
pb = LB->next;
pc = LC;
LC = pc;
while (true)
{
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;
free(LB);
return LC;
}
}
int main()
{
int data1[10] = {2,5,7,9,10,12,14,16,17,18};
int data2[10] = {1,3,4,11,12,14,15,16,17,18};
LNode *A, *B,*LC;
//LinkList LC;
A = create(data1, 10);
B = create(data2, 10);
LC = (LNode *)malloc(sizeof(LNode));
display(A);
display(B);
Unionlist(A, B, LC);
display(LC);
}
程序错在哪儿了 求大佬解答
#include "stdlib.h"
#define ElemType int
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
LNode *create(ElemType data[],int n)//创建
{
LNode *head, *p, *rear;
int k;
head = (LNode *)malloc(sizeof(LNode));
head->next = NULL;
rear = head;
for (k = 0; k < n; k++)
{
p = (LNode *)malloc(sizeof(LNode));
p->data = data[k];
p->next = NULL;
rear->next = p;
rear = p;
}
return head;
}
void display(LNode *head)//显示
{
LNode *p;
p = head->next;
while (p)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
LinkList Unionlist(LNode *LA, LNode *LB, LNode *LC//
{
LNode *pa, *pb, *pc;
pa = LA->next;
pb = LB->next;
pc = LC;
LC = pc;
while (true)
{
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;
free(LB);
return LC;
}
}
int main()
{
int data1[10] = {2,5,7,9,10,12,14,16,17,18};
int data2[10] = {1,3,4,11,12,14,15,16,17,18};
LNode *A, *B,*LC;
//LinkList LC;
A = create(data1, 10);
B = create(data2, 10);
LC = (LNode *)malloc(sizeof(LNode));
display(A);
display(B);
Unionlist(A, B, LC);
display(LC);
}
程序错在哪儿了 求大佬解答