第二个
#include
using namespace std;
#include
struct hero
{
string sex;
int age;
string name;
};
void bubblesort(struct hero herroarray[], int len)
{
for (int i = 0; i < len-1; i++)
{
for (int j = 0; j < len - 1 - i; j++)
{
if (herroarray[j].age>herroarray[j + 1].age)
{
struct hero temp;
temp = herroarray[j];
herroarray[j] = herroarray[j + 1];
herroarray[j + 1] = temp;
}
}
}
}
void printherro(struct hero herroarray[], int len)
{
for (int i = 0; i < len; i++)
{
cout <<" 姓名: “<< herroarray[i].name
<<” 年龄"<< herroarray[i].age
<<" 性别"<< herroarray[i].sex<<endl;
}
}
int main()
{
struct hero herroarray[5] = { { "刘备", 23, "男" }, { "关羽", 22, "男" }, { "张飞", 20, "男" }, { "赵云", 21, "男" }, { "貂蝉", 19, "女" }, };
int len = sizeof(herroarray) / sizeof(herroarray[0]);
bubblesort(herroarray, len);
printherro(herroarray, len);
system("pause");
return 0;
}