#include <iostream>
using namespace std;
#include <string.h>
struct hero {
string name;
int age;
};
void bubblesort(struct hero s[], int len) {
for (int i = 0; i < len-1; i++) {
for (int j = 0; j < len - 1 - i; j++) {
if (s[j].age > s[j + 1].age) {
struct hero temp = s[j];
s[j] = s[j + 1];
s[j + 1] = temp;
}
}
}
}
void printcc(struct hero s[], int len) {
for (int i = 0; i < len; i++) {
cout << "姓名 " << s[i].name << "年龄 " << s[i].age << endl;
}
}
int main() {
struct hero s[3] = {
{"一",20},
{"二",18},
{"三",30},
};
int len = sizeof(s) / sizeof(s[0]);
bubblesort(s, len);
printcc(s, len);
system("pause");
return 0;
}