8.8.1案例2

8.8.1案例2

#include 
using namespace std;
#include
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; iihe[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;
}

你可能感兴趣的:(蓝桥杯,c++,c语言)