| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 600 人关注过本帖
标题:链表运用出的问题
取消只看楼主 加入收藏
hbqcgyxyjsj
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-10-20
收藏
 问题点数:0 回复次数:1 
链表运用出的问题

 我写了程序,老师要求用链表。结果出了个问题怎么也改不了。提示说INSERT函数有问题。大家帮忙看看?

#define NULL0 #define LEN sizeof (struct student) #include <stdio.h> struct student {long num; char name [20]; char sex; int age; float score [10] ; struct students*next; }; int n ,i, score [10]; struct student*create() {struct student *head,*p1,*p2; n=0; head=NULL; p1=(struct student *)malloc(LEN); scanf("%d%c%c%d",&p1->num,p1->name[20],&p1->sex,&p1->age); for(i=0;i<10;i++) {scanf("%d",&score[i]);}; p1->next=NULL; while(p1->num!=0) {++n; if(n==1)head=p1; else p2->next=p1; p2=p1; p1=(struct student*)malloc(LEN); scanf("%d%c%c%d",&p1->num,p1->name[20],&p1->sex,&p1->age); for(i=0;i<10;i++) scanf("%d",&score[i]); p1->next=NULL; }free(p1); return(head); } struct student *insert(struct student *head,struct student *stud) {struct student *p0,*p1,*p2; p1=head; p0=stud; if(head==NULL) {head=p0;p0->next=NULL;} else {while((p0->num>p1->num)&&(p1!=NULL)) {p2=p1;p1=p1->next;} if(head==p1) {head=p0; p0->next=head;} else

{p2->next=p0; p0->next=p1; } ++n; return (head); } struct student *delete(struct student *head,long num) {struct student *p1,*p2; if(head==NULL) goto end; else p1=head; while((num!=p1->num)&&(p1->next!=NULL)) {p2=p1;p1=p1->next;} if(num==p1->num) {if(p1==head) head=p1->next; else p2->next=p1->next; printf("delete:%d\n",num); free(p1); n--; } else printf("%d not been found!\n",num); end:return(head); } struct student *find(struct student *head,long num) {struct student p1,*p2; int i; if(head==NULL) {printf("\n list NULL!\n");goto end;} p1=head; while((num!=p1->num)&&(p1!=NULL)) {p2=p1;p1=p1->next;} if(p1!=NULL) {printf("find:%d%c%c%d",num,name,sex,age); for(i=0;i<10;i++) printf("%d",score[i]); } else printf("%d not been found!\n",num); end: return(head); } float aver(float score[]) {int i; for(i=0;i<10;i++) aver+=score[i]; aver=aver/10; return(aver); } float highest(float score[]) {int i; highest=score[0]; for(i=1;i<10;i++) {if(score[i]>highest) highest=score;} return(highest); } float lowest(float score[]) {int i; lowest=score[0]; for(i=1;i<10;i++) {if(lowest>score[i]) lowest=score[i]; } return lowest; } main() {char a; printf("Welcome to students' MIS!\n"); scanf("%c",&a); switch(a) {case I:struct student*insert(struct student*head,struct student*stud);break; case D:struct student*delete(struct student*head,long num);break; case F:struct student*find(struct student*head,long num);break; case C:float aver(float score[])}; float highest(float score[]); float lowest(float score[]);break; case Q:printf("\n"); } }

搜索更多相关主题的帖子: 链表 
2005-10-20 12:22
hbqcgyxyjsj
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-10-20
收藏
得分:0 
那具体应该怎么分配呢?
2005-10-20 22:59
快速回复:链表运用出的问题
数据加载中...
 
   



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

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