建立一个链表,输入学生成绩.然后排序输出.程序如下:我在程序中用pp()函数建立链表,用aa()排序.但运行时,只输入一组数据后,就结束了.运行结果出现提示为:scanf:floating point formats not linked Abnormal program termination 程序如下: #include <malloc.h> #define NULL 0 #define LEN sizeof(struct student) struct student {long num; float score; struct student *next; }; int n; struct student *pp(void) {struct student *head; struct student *p1,*p2; n=0; p1=p2=(struct student *)malloc(LEN); scanf("%ld,%f",&p1->num,&p1->score); 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",&p1->num,&p1->score); } p2->next=NULL; return(head); }
struct student *aa(void) {struct student *a,*b;long c;float d; struct student *head; head=pp(); for(a=head;a->next!=NULL;a=a->next) for(b=a->next;b!=NULL;b=b->next) {if(b->score>a->score) {c=a->num;a->num=b->num;b->num=c;d=a->score;a->score=b->score;b->score=d;} } return(head); }
main() {struct student *p;int i=1; p=aa(); do{ printf("%d,%ld,%f\n",i,p->num,p->score); p=p->next;i++;} while(p!=NULL); }