结构体指针冒泡排序代码
时间: 2023-09-08 19:14:19 浏览: 52
好的,以下是结构体指针冒泡排序代码:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student {
char name[10];
int age;
float score;
};
typedef struct student *Student;
int sort(Student stu[], int len) {
int i, j, flag = 1;
Student temp;
for (i = 0; i < len - 1 && flag; i++) {
flag = 0;
for (j = 0; j < len - i - 1; j++) {
if (stu[j]->score > stu[j+1]->score) {
flag = 1;
temp = stu[j];
stu[j] = stu[j+1];
stu[j+1] = temp;
}
}
}
return 0;
}
int main() {
Student stu[3];
int i;
for (i = 0; i < 3; i++) {
stu[i] = (Student)malloc(sizeof(struct student));
printf("请输入第%d个同学的信息:\n", i+1);
printf("姓名:");
scanf("%s", stu[i]->name);
printf("年龄:");
scanf("%d", &(stu[i]->age));
printf("成绩:");
scanf("%f", &(stu[i]->score));
}
sort(stu, 3);
printf("排序后的结果为:\n");
for (i = 0; i < 3; i++) {
printf("%s\t%d\t%f\n", stu[i]->name, stu[i]->age, stu[i]->score);
free(stu[i]);
}
return 0;
}
```
请问还有什么其它问题?