Java??-e??????
???????????? ???????[ 2014/6/25 15:56:57 ] ????????Java?? e??????
???????:
????e??????BubbleSort?????????????????α?????????????????С????????棬??????????檔????????????????1?????2????????С????????????????????2???????3????????С???????????????????????????????????????С??????????????
?????????????????????????????????????????????????????????????????2???????3???????????????1????????С???2??????????С??????????????????????????????????????????λ??????????????????????????????????λ??????????μ?????????????????????????????????????????????????????????????????
???????????????????????С?????????????????????????????????????????e??????
????????????????????????????i??????????????j????????10?????????????????????????9?Σ?????????????9??8??...??1?Ρ???ν??б????????????????????j?й??????????????a[j]??a[j+1]?????i????????1??2??...??9??????????i??j????????1??2??...10-i??
????????:
public static void main(String[] args) {
int[] i = {1001??596??403??39??23??12??9??6??5??4??3??1};
bubbleSort(i);
}
private static void show(int[] x) {
for (int i:x) {
System.out.print(i + " ");
}
System.out.println();
}
public static void bubbleSort(int[] a) {
int temp;
show(a);
for (int i = a.length - 1;i > 0;i--) {
System.out.println("----------Round " + (a.length - i) + "-----------");
for (int j = 0;j < i;j++) {
if (a[j] > a[j + 1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
show(a);
}
}
}
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11