这个链表是什么意思 而且有一处错误
#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
float score;
struct *next;
} ;
int n;/*n为全局变量*/
struct student *creat(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++;
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
{long num;
float score;
struct *next; //应写成struct student * next;
} ;
这是最简单的单链表,create实现链表创建
其他:楼上正解,一般不使用链表进行排序,移动比较费时。
排序的话,可以用最简单的冒泡。 enen
上一个:C语言,有劳各位帮我看看是什么问题。
下一个:C++代码写密码的三次验证。输入错误的时候,提示错误,当正确的时候提示进入。