如何逆序链表?
#include "stdio.h"#include "string.h"
#include "malloc.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
char name[20];
struct student *next;
};
int n;
struct student * create(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=(struct student *)malloc(LEN);
scanf("%ld,%f,%s",&p1->num,&p1->score,p1->name);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%f,%s",&p1->num,&p1->score,&p1->name);
}
p2->next=NULL;
return (head);
}
struct print(struct student *head)
{
struct student *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
{
do
{
printf("%ld%5.1f%4s\n",p->num,p->score,p->name);
p=p->next;
}while(p!=NULL);
}
}
struct nixu(struct student *head)//这段函数该如何些逆序链表的代码?
{
}
int main(int argc, char* argv[])
{
struct student *head,stu;
long del_num;
printf("input records:\n");
head=create();
print(head);
return 0;
}