forked from Jossc/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
41 lines (35 loc) · 991 Bytes
/
BubbleSort.java
File metadata and controls
41 lines (35 loc) · 991 Bytes
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
33
34
35
36
37
38
39
40
41
package com.algorithm;
import java.util.Arrays;
/**
* @ClassName BubbleSort
* @Author chenzhuo
* @Version 1.0
* @Date 2019-08-17 21:47
**/
public class BubbleSort {
public static void main(String[] args) {
int[] array = new int[]{5, 8, 6, 3, 9, 2, 1, 7};
sort(array);
System.out.println(Arrays.toString(array));
}
public static void sort(int[] array) {
int tmp = 0;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length - i - 1; j++) {
if (array[j] > array[j + 1]) {
tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}
}
public static void sort2(int[] array) {
int tmp = 0;
for (int i = 0; i < array.length; i++) {
boolean isSorted = true;
for (int j = 0; j < array.length - i - 1; j++) {
}
}
}
}