#import
typedefstruct student{
char
name[30];
int age;
float
score;
float
height;
float
weight;
int
studentID;
char sex;
float
birthday;
}Student;
// 打印学生数组的方法
void printStudentArray(Student *p ,int
count)
{
printf("姓名\t年龄\t成绩\t\t身高\t\t体重\t\t学号\t\t性别\t\t生日\t\t\n");
for
(int i = 0; i < count;
i++) {
printf("%s\t%d\t%.2f\t\t%.2f\t\t%.2f\t\t%d\t\t%c\t\t%.2f\t\t\n"
, (p+i)->name , (p+i)->age ,
(p+i)->score , (p+i)->height ,
(p+i)->weight , (p+i)->studentID ,
(p+i)->sex , (p+i)->birthday);
}
}
//typedef int ThreeInt (int , int);
// 年龄
BOOL byAge(Student stu1 , Student stu2)
{
return stu1.age >
stu2.age;
}
// 成绩
BOOL byScore(Student stu1 , Student stu2)
{
return
stu1.score > stu2.score;
}
// 身高
BOOL byHeight(Student stu1 , Student stu2)
{
return
stu1.height > stu2.height;
}
// 体重
BOOL byWeight(Student stu1 , Student stu2)
{
return
stu1.weight > stu2.weight;
}
// 学号
BOOL byStudentID(Student stu1 , Student stu2)
{
return
stu1.studentID > stu2.studentID;
}
// 生日
BOOL byBirthday(Student stu1 , Student stu2)
{
return
stu1.birthday > stu2.birthday;
}
typedef BOOL boolFunctionPoint
(Student , Student);
typedefstruct chieng{
char
hanzi[30];
boolFunctionPoint
*hanshudizhi;
}Chieng;
void sortedAll(Student *stus , int
count , char *name)
{
Chieng age =
{"年龄" , byAge};
Chieng height =
{"身高" , byHeight};
Chieng score =
{"成绩" , byScore};
Chieng studentID =
{"学号" , byStudentID};
Chieng weight =
{"体重" , byWeight};
Chieng birthday =
{"生日" , byBirthday};
Chieng jiegoutiArray[] =
{age , height , score , studentID , weight , birthday};
boolFunctionPoint *p =
nil;
for
(int i = 0; i <
6; i++) {
if (strcmp(name,
jiegoutiArray[i].hanzi) == 0) {
p =
jiegoutiArray[i].hanshudizhi;
break;
}
}
if (p !=
nil) {
for (int i =
0; i < count - 1; i++)
{
for (int j = 0; j
< count - 1 - i; j++) {
if (p(stus[j] ,
stus[j + 1])) {
Student temp;
temp = *(stus + j);
*(stus + j) = *(stus + j + 1);
*(stus + j + 1) = temp;
}
}
}
}
printStudentArray(stus, count);
}
int main(int argc, const
char * argv[]) {
// 准备好一个指针变量出来
Student stu1 =
{"蛮子" , 26 ,
34.6 , 174 , 68 ,
101 , 'm' , 10.12};
Student stu2 =
{"剑圣" , 24 ,
24.6 , 170 , 60 ,
102 , 'm' , 10.11};
Student stu3 =
{"亚索" , 27 ,
64.6 , 179 , 65 ,
125 , 'm' , 10.13};
Student stu4 =
{"薇恩" , 20 ,
84.6 , 171 , 48 ,
134 , 'f' , 10.16};
Student stu5 =
{"石头人" , 50 ,
74.6 , 180 , 100 ,
156 , 'm' , 10.14};
Student stu6 =
{"盖伦" , 29 ,
14.6 , 181 , 70 ,
178 , 'm' , 10.18};
Student stu7 =
{"赵信" , 22 ,
54.6 , 176 , 69 ,
189 , 'm' , 10.15};
Student stu8 =
{"崔斯特" , 30 ,
94.6 , 178 , 66 ,
196 , 'm' , 10.17};
Student students[] = {stu1
, stu2 , stu3 , stu4 , stu5 , stu6 , stu7 , stu8};
sortedAll(students,
8, "身高");
return
0;
}