帮忙看下这单链表逆置哪出问题了
#include<stdio.h>#include<malloc.h>
typedef int datatype;
typedef struct link_node{
datatype info;
struct link_node *next;
}node;
node *lianbiao(void)
{
int i=0;
node *head, *p1, *p2;
p1=p2=(node*)malloc(sizeof(node));
scanf("%d",&p1->info);
head=NULL;
while(p1->info!=0)
{
i=i+1;
if(i==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(node*)malloc(sizeof(node));
scanf("%d",&p1->info);
}
p2->next=NULL;
return(head);
}
node *ReverseList(node *head)
{
node *p1, *p2, *r;
p1 = head;p2=r=NULL;
while(p1) { p2 = p1->next;
p1->next = r;
r = p2;
p1 = p2;
}
return r;
}
void shuchu(node *head)
{
node *p1;
p1= head;
while(p1)
{
printf("%d\n", p1->info);
p1 = p1->next;
}
}
int main(void)
{
node *head;
head = lianbiao();
printf("链表逆置前的数据:\n");
shuchu(head);
head = ReverseList(head);
printf("链表逆置后的数据:\n");
shuchu(head);
return 0;
}