合并两个链表,可是运行不通过耶~请各位高手帮忙看看错在哪里?
#include "stdio.h"#include "malloc.h"
struct node
{
int data;
struct node *next;
};
struct node * creat(void)
{
struct node *p1,*p2,*head;
p2=p1=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p1->data);
head=p1;
while(p1->data!=NULL)
{
p1=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p1->data);
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(head);
}
struct node * print(struct node *head)
{
struct node *p; int sum=0;
printf("the data of the list are:\n");
p=head;
while(p->next!=NULL)
{
printf("%d ",p->data);
p=p->next;sum++;
}
}
struct node * connect(struct node *hx,struct node *hy)
{
struct node *p,*hz;
p=hx;
while(p->next!=NULL)
p=p->next;
p->next=hy;
hz=hx;
return(hz);
}
main()
{
struct node *hx,*hy,*hz;
printf("please enter the data of X");
hx=creat();
print(hx);
printf("please enter the data of Y");
hy=creat();
print(hy);
hz=connect(hx,hy);
print(hz);
}