链表逆置,帮忙看一下!
#include<stdio.h>#include<malloc.h>
struct stu
{
int num;
struct stu *next;
};
struct stu *creat()
{
struct stu *head,*p;
int k;
head=NULL;
printf("请输入一个数字:");
scanf("%d",&k);
while(k!=0)
{
p=(struct stu *)malloc(sizeof(struct stu));
p->num=k;
p->next=head;
head=p;
printf("请输入一个数字:");
scanf("%d",&k);
}
return head;
}
struct stu *daoxu(struct stu *head)
{
struct stu *p,*q,*r;
p=head;
q=NULL;
while(p!=NULL)
{
r=q;
q=p;
p=p->next;
q->next=r;
}
return head;
}
void print(struct stu *head)
{
struct stu *p;
p=head;
while(p->next!=NULL)
{
printf("%d ",p->num);
p=p->next;
}
}
void main()
{
struct stu *head;
head=creat();
head=daoxu(head);
print(head);
}
请高手帮我看一下这个程序,为什么输完k就结束了,该程序实现的是链表逆置!
[ 本帖最后由 雨也有梦 于 2013-4-6 09:16 编辑 ]