public static void bubbleSort(int [] nums) {
for(int i=0; i < nums.length-1; i++) {
for(int j=0; j < nums.length-i-1; j++) {
if(nums[j] > nums[j+1]) {
int temp = nums[j];
nums[j] = nums[j+1];
nums[j+1] = temp;
}
}
}
}
/**
* 选择排序
* @param array
*/
public static void selectSort(int [] array) {
int minIndex;
for(int i=0; i < array.length - 1; i++) {
minIndex = i;
for(int j=i+1; j < array.length; j++) {
if(array[j] <array[minIndex]) {
minIndex = j;
}
}
int temp = array[i];
array[i] = array[minIndex];
array[minIndex] = temp;
}
}
public static void insertionSort(int [] array) {
for(int i = 1; i < array.length; i++) {
int preIndex = i - 1;
int current = array[i];
while(preIndex >= 0 && array[preIndex] > current) {
array[preIndex + 1] = array[preIndex];
preIndex--;
}
array[preIndex + 1] = current;
}
}