这是我的结构体链表
放到第二个 for 循环里面使用 p=move->next
结构体里没有 zong 的成员变量, 这么改下,供参考:
#include <stdio.h>
#include <stdlib.h>
typedef struct _student {
char num[20];
char name[20];
int sex;
float BMI;
int fei;
int up;
float score[3];
char level[15];
}Student;
typedef struct _Node {
Student student;
struct _Node* next;
}Node;
void swap(Student& stu1, Student& stu2)
{
Student temp;
temp = stu1;
stu1 = stu2;
stu2 = temp;
}
void paixu1(Node *head)
{
Node* p = NULL, * pre = NULL;
for (p = head->next; p->next != NULL; p = p->next)
for (pre = p->next; pre != NULL; pre = pre->next)
if(p->student.score[0] < pre->student.score[0]) //按单科成绩score[0]排名,从高到低
swap(p->student, pre->student);
}