package io.github.chenshun00.web.sort;
import java.util.Arrays;
/**
* @author luobo.cs@raycloud.com
* @since 2021/8/12 9:44 上午
*/
public class BubbleSort {
public static void main(String[] args) {
int[] array = {9, 8, 7, 6, 5, 4, 3, 2, 1};
sort(array);
System.out.println(Arrays.toString(array));
}
public static void sort(int[] array) {
for (int i = 0; i < array.length; i++) {
final int i1 = array[i];
int j = i + 1;
for (; j <= array.length - 1; j++) {
final int j2 = array[j];
if (i1 > j2) {
swap(array, i, j);
}
}
}
}
public static void swap(int[] array, int a, int b) {
int temp = array[a];
array[a] = array[b];
array[b] = temp;
}
}