高手们来帮忙啊,就要交作业了.链表的问题.
我们教师布置了一道题,就是建立一个存每个学生成绩的链表,然后按照总成绩的高低输出链表. 我的程序如下,没有排序.但都有问题,问题出在哪里啊,怎样排序啊. #include <malloc.h> #define NULL 0 #define LEN sizeof(struct student> struct student {long num; float sco; 总分. struct student *next; }; int n;
struct student *pp(void) {struct student *head; struct student *p1; struct student *p2; n=0; p1=p2=(struct student *)malloc(LEN); scanf("%ld,%f",&p1->num,&p1->sco); 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); } P2->next=NULL; return(head); }
main() {struct student *p; p=pp(); do{ printf("%ld,%f"p->num,p->sco);p=p->next} while(p!=NULL); }