问题遇到的现象和发生背景
到这就想不出来了,有没有大神会的。。
main函数需要呼出bubble_sort_countries
问题相关代码,请勿粘贴截图
#include <stdio.h>
#define COUNTRYNO 4
void bubble_sort_countries(int countries[COUNTRYNO],int n){
int i,j,tmp;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i - 1; j++) {
if (countries[j] > countries[j + 1]) {
tmp = countries[j];
countries[j] = countries[j + 1];
countries[j + 1] = tmp;
}
}
}
}
struct Country {
char country_name[50];
int population;
};
int find_most_populated( struct Country * );
int main( void ) {
struct Country countries[COUNTRYNO] = {
{ "United States", 331 },
{ "China", 1439 },
{ "Japan", 126},
{ "Brazil", 212 }
};
bubble_sort_countries(countries[], 5);
for (i = 0; i < 5; i++) {
printf("%d ", countries[i]);
}
我的解答思路和尝试过的方法
我想要达到的结果
List of most populated countries
- Country: China, Population: 1439 million
- Country: United States, Population: 331 million
- Country: Brazil, Population: 212 million
- Country: Japan, Population: 126 million