学生成绩排序问题
# include <stdio.h># include <malloc.h>
# include <stdlib.h>
struct Students
{
int Sid;
char Name[20];
char Gender;
float Score;
};
void InputData(struct Students * , int len);
void OutputData(struct Students * , int len);
void Rank(struct Students * , int len );
int main (void)
{
int len;
printf ("请输入学生人数:\n");
printf ("len = ");
scanf ("%d", &len);
struct Students * Pst;
Pst = (struct Students *)malloc(sizeof(struct Students) * len);
InputData(Pst, len);
Rank(Pst, len);
OutputData(Pst, len);
system("pause");
return 0;
}
void InputData(struct Students * pst, int len)
{
int i;
for (i = 0; i < len; i++)
{
printf ("请输入第 %d 个学生的信息:\n", i+1);
printf ("Sid = ");
scanf ("%d", &pst[i].Sid);
printf ("Name = ");
scanf ("%s", pst[i].Name);
printf ("Gender = ");
scanf ("%*c%c", &pst[i].Gender);
printf ("Score = ");
scanf ("%f", &pst[i].Score);
}
}
void OutputData(struct Students * pst, int len)
{
int i;
for(i = 0; i < len; i++)
{
printf ("\n\n第 %d 个学生的信息如下:\n", i+1);
printf ("Sid = %d\n", pst[i].Sid);
printf ("Name = %s\n", pst[i].Name);
printf ("Gender = %c\n", pst[i].Gender);
printf ("Score = %f\n", pst[i].Score);
}
}
//以下是错的。
void Rank (struct Students * pst, int len)
{
struct Students st;
int i;
for (i = 0; i < len; i++)
{
if (pst[i].Score < pst[i+1].Score)
{
st = pst[i];
pst[i] = pst[i+1];
pst[i+1] = pst[i];
}
}
}
请问我哪错了?使用Rank函数进行冒泡排序