Skip to content

Commit 4b08d21

Browse files
chinagoodmanchinagoodman
authored andcommitted
2018.04.13-18:12
冒泡排序
1 parent 299c318 commit 4b08d21

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

src/com/ljj/algorithm/sort/BubbleSort.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,49 @@
33
public class BubbleSort {
44

55
public static void main(String[] args) {
6-
// TODO Auto-generated method stub
7-
6+
//待排序数组
7+
int[] array = {99,45,101,2,36,55,4,88,898};
8+
System.out.println("排序前数组: ");
9+
//输出排序前数组
10+
printArray(array);
11+
12+
//排序后数组
13+
int[] sortArray = sort(array);
14+
System.out.println("排序后数组: ");
15+
//输出排序后数组
16+
printArray(sortArray);
817
}
918

19+
/**
20+
* 冒泡排序
21+
* @Title: sort
22+
* @param array
23+
* @return int[]
24+
* @throws
25+
*/
26+
public static int[] sort(int[] array) {
27+
int isChange = 0;
28+
for (int i = 0; i < array.length - 1; i++) {
29+
for(int j = 0; j < array.length - i -1; j++) {
30+
31+
}
32+
}
33+
return null;
34+
}
35+
36+
/**
37+
* 打印数组
38+
* @Title: printArray
39+
* @param array
40+
* @throws
41+
*/
42+
public static void printArray(int[] array) {
43+
for (int i : array) {
44+
if(i == array.length - 1) {
45+
System.out.print(i);
46+
}else {
47+
System.out.print(i + ",");
48+
}
49+
}
50+
}
1051
}

0 commit comments

Comments
 (0)