看看这代码哪错了
#include<iostream>#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define NULL 0
#define LEN sizeof(node)
typedef int elemtype;
struct node
{
elemtype data;
struct node*next;
};
struct node*Createlist()
{
node*head=NULL,*p=NULL,*r=NULL;
head=(node*)malloc(LEN);
r=head;
cout<<"请输入链表的长度:"<<endl;
int n,temp;
cin>>n;
cout<<"请按顺序输入链表元素:"<<endl;
for(int i=0;i<n;i++)
{
p=(node*)malloc(LEN);
cin>>temp;
p->data=temp;
r->next=p->next;
r=p;
}
return (head);
}
void Traverser(struct node*head)
{
if(head->next==NULL)
{
cout<<"Error!"<<endl;
exit(1);
}
else
{
node*r=head->next;
while(r!=NULL)
{
cout<<r->data<<" ";
r=r->next;
}
}
}
int IsEmpty(struct node*head)
{
if(head->next==NULL)
return 1;
else
return 0;
}
void Mergelist(node*La,node*Lb,node*Lc)
{
node*pa=NULL,*pb=NULL,*pc=NULL;
Lc=pc=La;
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 main()
{
struct node*La=NULL,*Lb=NULL,*Lc=NULL,*p;
La=Createlist();
Lb=Createlist();
Mergelist(La,Lb,Lc);
p=Lc->next;
if(p==NULL)
{
cout<<"biao wei kong"<<endl;
}
else
{
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
}
}
大家看下,调试没错,运行有问题。。。急啊