1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package 数组;
public class BubbleSort {
public static void main(String[] args) {
int [] array = { 63 , 4 , 24 , 1 , 3 , 15 };
BubbleSort sorter = new BubbleSort();
sorter.sort(array);
}
public void sort( int [] array) {
for ( int i = 1 ; i < array.length; i++) {
for ( int j = 0 ; j < array.length - i; j++) {
if (array[j] > array[j + 1 ]) {
int temp = array[j];
array[j] = array[j + 1 ];
array[j + 1 ] = temp;
}
}
}
showArray(array);
}
public void showArray( int [] array) {
for ( int i : array) {
System.out.println( ">" + i);
}
System.out.println();
}
}
|
本文转自杰1992 51CTO博客,原文链接:http://blog.51cto.com/holger/1937096,如需转载请自行联系原作者