#include "stdio.h"
#include "malloc.h"
typedef struct node
{
int data;
int *next;
};
struct node * creat(int n)
{
struct node *head,*p1,*p2;
head=(struct node *)malloc(sizeof(struct node));
head=NULL;
head->next=p1; /*头指针指向p1*/
printf("enter data");
while(p1->data!=NULL)
{
p1->next=p2;
p1=(struct node *)malloc(sizeof(struct node));
scanf("%d ",&p1->data);
p2->next=p1;
}
return(head);
}
struct node * insert(struct node *x,struct node *y,struct node *z)
{
struct node *headz;int lx,ly;
headz=NULL;
headz->next=z;
if(lx>ly)
{
while(y->next!=NULL)
{
z=(struct node *)malloc(sizeof(struct node));
z->next=x;x=x->next;
z=(struct node *)malloc(sizeof(struct node));
z->next=y;y=y->next;
}
while(x->next!=NULL)
{
z=(struct node *)malloc(sizeof(struct node));
z->next=x;x=x->next;
}
}
else
{
while(x->next!=NULL)
{
z=(struct node *)malloc(sizeof(struct node));
z->next=x;x=x->next;
z=(struct node *)malloc(sizeof(struct node));
z->next=y;y=y->next;
}
while(y->next!=NULL)
{
z=(struct node *)malloc(sizeof(struct node));
z->next=y;y=y->next;
}
}
return(headz);
}
struct node * print(struct node *z)
{
do
{
printf("%d ",z->data);
z=z->next;
}while(z->next!=NULL);
return(z);
}
main()
{
struct node *hx,*hy,*hz;
int lx,ly; /*输入X,Y的项数即长度*/
printf("enter lx,ly:\n");
scanf("%d %d",&lx,&ly);
printf("\n creat hx \n");
hx=struct node * creat(lx);
print("hx");
printf("\n creat hy \n");
hy=struct node * creat(ly);
print(hy);
hz=struct node * insert(*hx,*hy,*hz);
print(hz);
}
我自己写的,可是老无法通过,而且还有语法错误,可我找不出来了。