

这算哪种排序?感觉都不像,但是最终可以正确排序。
source link: https://www.oschina.net/question/2507499_2321870
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

这算哪种排序?感觉都不像,但是最终可以正确排序。
public static void main(String[] args) { int[] a = {11, 454, 21, 2, 9}; bubbleSort(a); System.out.println("结果:" + Arrays.toString(a)); } private static void bubbleSort(int[] a) { for (int i = 0; i < a.length; i++) { for (int j = 0; j < a.length; j++) { if (a[i] < a[j]) { int temp = a[i]; a[i] = a[j]; a[j] = temp; System.out.println("i-" + i + " j-" + j + " " + Arrays.toString(a)); } } } }
打印结果:
i-0 j-1 [454, 11, 21, 2, 9]
i-1 j-0 [11, 454, 21, 2, 9]
i-2 j-1 [11, 21, 454, 2, 9]
i-3 j-0 [2, 21, 454, 11, 9]
i-3 j-1 [2, 11, 454, 21, 9]
i-3 j-2 [2, 11, 21, 454, 9]
i-4 j-1 [2, 9, 21, 454, 11]
i-4 j-2 [2, 9, 11, 454, 21]
i-4 j-3 [2, 9, 11, 21, 454]
结果:[2, 9, 11, 21, 454]
看打印不像是冒泡, 看代码不像插入排序
Recommend
-
106
这算不算是挣制度红利的钱? - 一签众安,一签阅文,一签雷蛇,一签易鑫(30手确保中一签),从9月18日的众安开始,只打葛总建议和强烈建议的,目前总共申购了这4个,加起来收益预计超过1.5万港币了,资金收益率25%+:)强烈推荐葛总亲自主持的港股打新路线图:...
-
89
全球工单系统 - @codeeer - 京东华硕自营 1080Ti,发来的 1080Ti 用的 1080 盒子装的,上面的编号和序列号都指向 1080,算二手实锤了吧,准备去法院了,胜算多大?![V2er]( https://i.loli.
-
40
这算违反交规么。。。
-
41
这算近景魔术了吧?
-
44
全球工单系统 - @peterpei - https://fbi.gs/imgs/2019/01/150b9ff654ab1090.gif第一次看到广告关不掉的
-
8
哪种情侣一看就感觉会在一起走得很远? 73回复 /10亮 152851 浏览 哪种情侣一看就感觉会在一起走得很远?
-
7
文案如何越写越好?这算是我压箱底的秘诀。 4周解锁小程序商业生态搭建与产品设计能力,抓住小程序红利,抢先成为稀缺人才! 立即了解>>...
-
8
感觉这次暴跌不像往年 没有故事,也没有解放军护盘传闻,更没人出来说两句话,就这样默默的一直跌... 真有点不习惯。 像中...
-
7
V2EX › 程序员 这算不算是静态类型系统的缺憾
-
5
V2EX › 问与答 你们周围真的有人用快手吗,感觉不像日活 3 亿多的 app
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK