#include<iostream>
using namespace std;
#include<string>
struct Hero {
string name;
int age;
string sex;
};
void bubbleSort(struct Hero HeroArray[],int len) {
for (int i = 0; i < len-1; i++)
{
for (int j = 0; j < len - 1 - i; j++) {
if (HeroArray[j].age > HeroArray[j+1].age) {
struct Hero temp = HeroArray[j];
HeroArray[j] = HeroArray[j + 1];
HeroArray[j + 1] = temp;
}
}
}
}
void printsort(struct Hero HeroArray[],int len){
for (int i = 0; i < len; i++) {
cout << "姓名: " << HeroArray[i].name << "年齡: " << HeroArray[i].age << "性別: " << HeroArray[i].sex << endl;
}
}
int main() {
struct Hero HeroArray[3] = { {"劉備",25,"男"},{"張飛",20,"男"},{"關羽",34,"男"}, };
int len = sizeof(HeroArray) / sizeof(HeroArray[0]);
for (int i = 0; i < len; i++) {
cout <<"姓名: "<< HeroArray[i].name << "年齡: "<<HeroArray[i].age<<"性別: "<<HeroArray[i].sex<<endl;
}
bubbleSort(HeroArray, len);
printsort(HeroArray, len);
return 0;
}