排序算法-----冒泡排序
public class BubbleSort {
public static void main(String[] args) {
int[] array = {-1, 0, 18, 25, 99, 10};
bubbleSortAsc(array);
bubbleSortDesc(array);
}
/**
* 冒泡排序:降序排序
*
* @param array
*/
public static void bubbleSortDesc(int[] array) {
for (int i = 0; i <= array.length - 1 ; i++) {
for (int j = i + 1; j < array.length; j++) {
if (array[i] < array[j]) {
int temp = 0;
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
System.out.println(Arrays.toString(array));
}
/**
* 冒泡排序:升序排序
*
* @param array
*/
public static void bubbleSortAsc(int[] array) {
for (int i = 0; i < array.length; i++) {
for (int j = i + 1; j < array.length ; j++) {
if (array[i] > array[j]) {
int temp = 0;
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
System.out.println(Arrays.toString(array));
}
}