c - 当我已经对它进行冒泡排序时,如何显示我的二维数组的索引?
问题描述
我的问题需要我显示我已经使用冒泡排序排序的数组的索引。但我不知道该怎么做。
int hdb[3][5] = {{5510, 5538, 5519, 5543, 5540},
{6627, 7656, 8603, 9201, 9404},
{3623, 4388, 4861, 5293, 5817}};
int j, temp;
printf("The number of applications for the 3-room HDB flat is:\n");
for (j = 0; j < 5; j++) {
if (hdb[0][j] > hdb[0][j + 1]) {
temp = hdb[0][j];
hdb[0][j] = hdb[0][j + 1];
hdb[0][j + 1] = temp;
}
printf("%d in index %d\n", hdb[0][j], j + 1);
}
它显示:
The number of applications for the 3-room HDB flat is:
5510 in index 1
5519 in index 2
5538 in index 3
5540 in index 4
5543 in index 5
但我的预期输出应该是:
The number of applications for the 3-room HDB flat is:
5510 in index 1
5519 in index 3
5538 in index 2
5540 in index 5
5543 in index 4
解决方案
推荐阅读
- tomcat - TOMCAT - catalina.properties - 自定义变量
- javascript - 删除复杂对象中的元素
- java - 从另一个类创建对象的类调用方法时出现 NullPointerException
- python - 关于 Neo4j + Flask 登录项目的问题
- typescript - 无法将 isoWeekDay 与矩变量一起使用
- python - Pandas 通过检查列表元素是否包含值进行选择
- r - 防止 R 自动获取已安装软件包的最新版本?
- javascript - 是否可以查看 JSON 文件中的多个对象分组?
- python - 如何编写一个递归函数来计算几年后的硬币净值?
- r - Optim() 函数以小数为单位变化?