标题:高手们来帮忙啊,就要交作业了.链表的问题.
只看楼主
qvbhsskg
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2005-4-28
 问题点数:0 回复次数:0 
高手们来帮忙啊,就要交作业了.链表的问题.

我们教师布置了一道题,就是建立一个存每个学生成绩的链表,然后按照总成绩的高低输出链表. 我的程序如下,没有排序.但都有问题,问题出在哪里啊,怎样排序啊. #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); }

搜索更多相关主题的帖子: 作业 链表 
2005-06-22 20:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-21377-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.134683 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved