#include <iostream>
using namespace std;
#include<string>
struct hero
{
string name;
int age;
bool sex;
};
void bubbles(struct hero he[], int len)
{
for (int i = 0; i < len - 1; i++)
{
for (int ii = 0; ii<len - i - 1; ii ++)
{
struct hero temp;
if (he[ii].age>he[ii+1].age)
{
struct hero temp = he[ii];
he[ii] = he[ii + 1];
he[ii + 1] = temp;
}
}
}
}
int main8_2_1()
{
struct hero he[5] =
{
{"刘备",23,true},
{ "关羽", 22, true },
{ "张飞", 20, true },
{ "赵云", 21, true },
{ "貂蝉", 19, false },
};
int len = sizeof(he) / sizeof(he[0]);
cout << len << endl;
bubbles(he,len);
for (int j = 0; j< 5; j++)
{
cout << he[j].name << he[j].age << he[j].sex << endl;
}
system("pause");
return 0;
}
8.8.1.结构体案例
最新推荐文章于 2024-10-09 10:07:13 发布