急求高人指点!!!!!!
#include<stdio.h>#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{int num;
struct student *next;
};
int n;
int i;
struct student *creat(void) //建立链表函数
{struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=( struct student* )malloc(LEN);
scanf("%d",&p1->num);
head=NULL;
while(p1->num)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=( struct student* )malloc(LEN);
scanf("%d",&p1->num);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)//打印出数据函数
{struct student* p;
printf("\nNow,These %d numbers are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%d ",p->num);
p=p->next;
}
while(p!=NULL);
}
struct student *paixv(struct student *head)//给输入数据排序函数
{struct student *p1,*p2;
if(head==NULL) {printf("\nlist null!\n");}
p1=head;
for(i=0;i<=n;i++)
{
while(p1->next!=NULL)
{if(p1->num>p1->next->num)
{n=p1->num;p1->num=p1->next->num;p1->next->num=n;
}
p1=p1->next;
}
if(p1->next==NULL)
p1=head;
}
return(head);
}
struct student *complex(struct student *head,struct student *stud)//两个链表合并
{struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{while((p0->num>p1->num)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{if(head==p1){head=p0;p0=p0->next;}
else {p2->next=p0;p0=p0->next;p0->next=p1;}
}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
return(head);
}
void main()
{ struct student *head,*stu;
printf("input numbers:\n");
head=creat(); //第一次调用建表函数
printf("\ninput another numbers:");
stu=creat(); //第二次调用
print(head);
paixv(head);
printf("\n输入数据非降序排列后为:");
print(head);
print(stu);
paixv(stu);
printf("\n输入数据非降序排列后为:");
print(stu);
complex(head,stu);
print(head);
}
急求高人指点,该程序目的在于将两个自由创建的链表合并到一个链表中,其可以编译成功,但第一次调用见表时可以弹出提示输入数据,而第二次却不能弹出,即是只能有一次数据输入,第一次输入完毕后,第二次直接跳过,默认链表为空了!