还是出错。。。
#include <stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define OVERFLOW -2
typedef int Status;
typedef struct LNode{
int data;
struct LNode *next;
}Lnode,*LinkList;
void CreatList_L(LinkList &L,int n )
{
L=(LinkList)malloc(sizeof(Lnode));
L->next=NULL;
int i,e;
LinkList p;
for(i=0;i<n;i++)
{
scanf("%d",&e);
p=(LinkList)malloc(sizeof(Lnode));
p->data=e;
//printf("%d ",p->data);
p->next=L->next;
L->next=p;
}
}
void MergeList_L(LinkList &La,LinkList &Lb,LinkList &Lc)
{
LinkList pa,pb,pc;
pa=La->next;
pb=Lb->next;
Lc=pc=pa;
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;
free(Lb);
}
void display(LinkList &Lc,int K)
{
LinkList P;
P=Lc->next;
while (K--)
{
printf("%d ",P->data);
P=P->next;
}
printf("\n");
}
int main()
{
LinkList La,Lb,Lc;
int m,n;
while (scanf("%d%d",&m,&n)!=EOF)
{
CreatList_L(La,m);
CreatList_L(Lb,n);
Lc=(LinkList)malloc((m+n)*sizeof(Lc));
MergeList_L(La,Lb,Lc);
display(Lc,m+n);
}
return 0;
}