/**
* 选择排序(简单选择排序)
* @author Cinn
*
*/
public class selectSort {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] array= {48,58,50,98,69,51,27,99,100};
selectsort(array);
printArray(array);
}
/**
* 简单选择排序算法接口
* @param a
*/
public static void selectsort(int[] a){
for (int i = 0; i < a.length; i++) {
int j = i+1;
int position = i;
int temp = a[i];
for (; j < a.length; j++) {
if(a[j]<temp){
temp = a[j];
position = j;
}
}
a[position] = a[i];
a[i] = temp;
}
* 打印数组
* @param array
public static void printArray(int[] array){
for(int i=0;i<array.length;i++){
System.out.println(array[i]);
}
}
选择排序是不稳定的排序、时间复杂度为T(o) = O(n^2)