有好几处错误和遗漏,帮你改了,你看下:
#include
#include
#define NULL 0
struct node
{
int Data;
struct node *next;
};
main()
{
struct node *p1,*q1,*head1;
struct node *p2,*q2,*head2;
struct node *p3,*q3,*head3;
int x,i;
p1=q1=head1=p2=q2=head2=p3=q3=head3=NULL;
scanf("%d",&x);
while(x!=-1)
{
p1=(struct node*)malloc(sizeof(struct node ));
p1->Data=x;
if(q1==NULL)
{
q1=p1;
q1->next=NULL;
head1=p1;
}
if(q1!=NULL)
{
q1->next=p1;
q1=p1;
}
scanf("%d",&x);
}
p1->next = NULL;
scanf("%d",&i);
while(i!=-1)
{
p2=(struct node*)malloc(sizeof(struct node ));
p2->Data=i;
if(q2==NULL)
{
q2=p2;
q2->next=NULL;
head2=p2;
}
if(q2!=NULL)
{
q2->next=p2;
q2=p2;
}
scanf("%d",&i);
}
p2->next = NULL;
p1=head1;
p2=head2;
p3=(struct node*)malloc(sizeof(struct node ));
q3=head3=p3;
while(p1!=NULL&&p2!=NULL)
{
if(p1->DataData)
{
//q3->Data = p1->Data;
q3->next=p1;
q3=p1;
p1=p1->next;
}
else
{
//q3->Data = p2->Data;
q3->next=p2;
q3=p2;
p2=p2->next;
}
if(p1==NULL)
q3->next=p2;
if(p2==NULL)
q3->next=p1;
}
if(q3!=NULL)q3->next=NULL;
p3=head3->next;
while(p3!=NULL)
{
printf("%d",p3->Data);
p3=p3->next;
}
}