#程序报错
#include <iostream>
#include<string>
using namespace std;
struct Hero
{
string hName;
int age;
string sex;
};
void bubbleSort(struct Hero heroArry[], int len)
{
for (int i = 0; i < len-1; i++)
{
for (int j = 0; j < len - i - i; j++)
{
if (heroArry[j].age >heroArry[j + 1].age)
{
struct Hero temp = heroArry[j];
heroArry[j] = heroArry[j + 1];
heroArry[j + 1] = temp;
}
}
}
}
void printHero(struct Hero heroArry[], int len)
{
for (int i = 0; i < len; i++)
{
cout << "Name: " << heroArry[i].hName
<< " age:" << heroArry[i].age
<< " Sex:" << heroArry[i].sex << endl;
}
}
int main() {
struct Hero heroArry[5] =
{
{"Liu",23,"Man"},
{"Guan",22,"Man"},
{"Zhang",20,"Man"},
{"Zhao",21,"Man"},
{"Diao",19,"Women"},
};
int len = sizeof(heroArry) / sizeof(heroArry[0]);
bubbleSort(heroArry, len);
printHero(heroArry, len);
system("pause");
return 0;
}
网上说是内存不够了,但是没找到合适的解决办法