wordpress网站弹窗插件,海淀区seo搜索引擎,网站建设wangzhii,兴盛优选购物平台下载java算法#xff1a;冒泡排序 冒泡排序#xff1a;不断遍历文件#xff0c;交换倒序的相邻元素#xff0c;直到文件排好顺序。冒泡排序的主要优点是容易实现#xff0c;冒泡排序通常会比选择排序、插入排序慢。 如#xff0c;对EXAMPLE 字母进行排序#xff1a; E X… java算法冒泡排序 冒泡排序不断遍历文件交换倒序的相邻元素直到文件排好顺序。冒泡排序的主要优点是容易实现冒泡排序通常会比选择排序、插入排序慢。 如对EXAMPLE 字母进行排序 E X A M P L E .开始 [A] E X [E] M P L .E移到了A之后A移到了最前面 A E [E] X L M P .L移到了E之后E移到了X前面 A E E [L] X M P .L移到了X前面 A E E L [M] X P ... A E E L M [P] X A E E L M P [X] Prettyprint java代码 public class Bubble { public static void main(String[] args) { int n 20; MyItem [] a new MyItem[n]; for (int i 0; i n; i) { a[i] new MyItem(); a[i].rand(); } for (int i 0; i n; i) { System.out.print(a[i] ); } bubble(a, 0, n); System.out.println(); print(a, n); } private static void print(MyItem a [], int n){ for (int i 0; i n; i) { System.out.print(a[i] ); } } public static void bubble(MyItem [] a, int l, int r){ for (int i l; i r; i) { for (int j r - 1; j i; j--) { compExch(a, j - 1, j); } } } public static boolean less(Item v, Item w){ return v.less(w); } public static void exch(Item [] a, int i, int j){ Item t a[i]; a[i] a[j]; a[j] t; } public static void compExch(Item [] a, int i, int j){ if(less(a[j],a[i])){ exch(a, i, j); } } } 转载于:https://www.cnblogs.com/wuyida/archive/2012/11/01/6301140.html