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 ;
}
}
}
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 ;
}
}
}
相关文章推荐
- select sort algorithm
- select_sort(选择法排序)==C++源代码
- Select Sort Algorithm
- JS排序方法(sort,bubble,select,insert)代码汇总
- Algorithm intro - Select Sort
- Select_full_join 与 Select_range_check 与Sort_merge_passes
- Select Sort in scala
- Select和Sort状态变量
- 数据结构基础(1) --Swap & Bubble-Sort & Select-Sort
- 排序——选择排序(Select sort)
- MySQL Select and Sort Status Variables
- 选择排序(select sort)
- 选择排序(Select_Sort)
- 数据结构基础(1) --Swap & Bubble-Sort & Select-Sort
- Python中的排序方法(Bubble Sort,Insert Sort,Select Sort,Merge Sort,Quick Sort)
- Sort Algorithm-->Select Sort
- 【数据结构笔记】快速排序(quick_sort)和快速选择(quick_select)--Python2.7
- select_sort
- 选择排序----select sort
- 第46课程 Spark 2.0实战之Dataset:sort、join、joinWith、randomSplit、sample、select、groupBy、agg、col等