您的位置:首页 > 其它

Select sort

2010-07-04 22:46 120 查看
public class Main {

public static void main(String[] args) {
int [] arr = {9,8,7,6,5,4,3,2,1,0};
selectSort(arr);
for(int i:arr)
System.out.println(i);
}

private static void selectSort(int []arr){
for (int i=0 ; i < arr.length -1 ; i++ )
{
int min = i;
for (int j=i ; j < arr.length ; j ++)
{
if (arr[j] < arr[min])
min = j ;
}
//first find the smallest one , then swap
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp ;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: