#include <iostream>
#include<ctime>
#include<cmath>
#include<string>
using namespace std;
struct hero
{
string name;
int age;
string six;
};
void print(hero h[], int len)
{
for (int i = 0; i < len; i++)
{
cout << "英雄姓名:" << h[i].name << endl;
cout << "英雄年龄:" << h[i].age << endl;
cout << "英雄性别:" << h[i].six << endl;
cout << "\n\n";
}
}
void bubble_sort(hero h[], int len)
{
int i, j;
for (i = 0; i < len - 1; i++)
{
for (j = 0; j < len - i - 1; j++)
{
if (h[j].age < h[j + 1].age)
{
hero temp=h[j];
h[j] = h[j + 1];
h[j + 1] = temp;
}
}
}
}
int main()
{
hero h[3]=
{
{"貂蝉",22,"女"},
{"关羽",32,"男"},
{"刘备",36,"男"}
};
int len = sizeof(h) / sizeof(h[0]);
//排序
bubble_sort(h,len);
//打印函数
print(h, len);
system("pause");
return 0;
}