#include <stdio.h> #include <malloc.h> #define NULL 0 #define LEN sizeof(struct student) struct student { int num; float score; struct student *next; }; int n=0; void main() { void print(struct student *head); struct student *creat(void); struct student *change(struct student *head); struct student *head; head=creat(); head = change(head); print(head); } struct student *creat(void) { struct student *head,*p1,*p2; p1 = p2 = (struct student *)malloc(LEN); head = p1; scanf("%d%f",&p1->num,&p1->score); if (p1->num==NULL) head = NULL; else { while(p1->num!=NULL) { n=n+1; p2 = p1; p1=(struct student *)malloc(LEN); scanf("%d%f",&p1->num,&p1->score); p2->next=p1; } p2->next=NULL; } return(head); } struct student *change(struct student *head) { struct student *p1,*p2,*p3; if (n==0) head = NULL; else { p1 = head; p2 = p1->next; p1->next = NULL; while (p2 != NULL) { p3 = p2->next; p2->next = p1; p1 = p2; p2 = p3; } head = p1; } return(head); } void print(struct student *head) { struct student *p1; if (head==NULL) printf("nothing/n"); else { p1=head; while (p1!=NULL) { printf("%d,%.2f/n",p1->num,p1->score); p1=p1->next; } } }