forked from Jossc/JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble.java
More file actions
30 lines (27 loc) · 739 Bytes
/
Bubble.java
File metadata and controls
30 lines (27 loc) · 739 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
package com.algorithm;
import java.util.Arrays;
/**
* @ClassName Bubble
* @Author chenzhuo
* @Version 1.0
* @Date 2019-08-17 21:34
**/
public class Bubble {
private 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 main(String[] args) {
int[] array = new int[]{5, 8, 6, 3, 9, 2, 1, 7};
sort(array);
System.out.println(Arrays.toString(array));
}
}