171 字
1 分钟
c++代码致使死机3次
#include <iostream>using namespace std;
struct Hero{ string name; int age; string sex;};
void bubblesort(struct Hero heroArray[], int len){ for (int i = 0; i < len-1; i++) { for (int j = 0; i < len - i - 1; j++) { if (heroArray[j].age > heroArray[j + 1].age) { struct Hero temp = heroArray[j]; heroArray[j] = heroArray[j + 1]; heroArray[j + 1] = temp; } } }}
void printHero(Hero heroArray[], int len){ for (int i = 0; i < len; i++) { cout << heroArray[i].name << " " << heroArray[i].age << " " << heroArray[i].sex << endl; }}int main(){ Hero heroArray[5] = { {"刘备",23,"男"}, {"关羽",22,"男"}, {"张飞",20,"男"}, {"赵云",21,"男"}, {"貂蝉",19,"女"}, };
int len = sizeof(heroArray) / sizeof(heroArray[0]);
bubblesort(heroArray, len);
}后来知道j敲成i了,但我没想到死循环会让电脑卡死,以前也写过.😂😂😂
评论