1.冒泡排序
package com.ysc.array;
import java.util.Arrays;
public class BubbleSort {
public static void main(String[] args) {
int[] a = {1, 3, 12, 600, 132, 323, 1324, 998, 38, 22};
System.out.println("before sort the array is:");
System.out.println(Arrays.toString(a));
System.out.println("after sort the array is:");
bubbleSort(a);
System.out.println(Arrays.toString(a));
}
public static void bubbleSort(int[] array){
int i = 0;
int j = 0;
int temp;
for(i = 0; i < array.length - 1; i++){
for(j = 0; j < array.length - i - 1; j++){
if(array[j] > array[j + 1]){
temp = array[j];
array[j] = array[j +1];
array[j +1] = temp;
}
}
}
}
}