package com.xtfggef;
public class SelectSort {
/**
* @param args
*/
public static void main(String[] args) {
int[] data = new int[]{2,3,4,1,9,8};
System.out.println("before sorted:");
for(int k=0; k<data.length; k++){
System.out.print(data[k]+" ");
}
System.out.println();
int length = data.length;
for(int i=0; i<length-1; i++){
int flag = i;
for(int j=i+1; j<length; j++){
if(data[flag]>data[j]){
flag = j;
}
}
if(flag!=i){
int temp=0;
temp=data[i];
data[i]=data[flag];
data[flag]=temp;
}
}
System.out.println("after sorted:");
for(int h=0; h<data.length; h++){
System.out.print(data[h]+" ");
}
System.out.println();
}
}
posted on 2012-08-08 23:39
地心引力 阅读(825)
评论(0) 编辑 收藏