标签:.so ram test 选择 ref stat splay ade return
package com.jdk8.SortTest;
public class SelectSortTest {
public static void main(String[] args){
int[] params = new int[]{1,9,5,2,7,4,3,8};
System.out.println("排序前的数据为:");
display(params);
selectSorted(params);
System.out.println("排序后的数据为:");
display(params);
}
public static void display(int[] arrays){
for(int i = 0;i < arrays.length;i++){
System.out.print(" " + arrays[i] + " ");
}
}
private static void selectSorted(int[] params) {
if(null == params || params.length < 1){
return ;
}
int min = 0;
int ref = 0;
for(int i = 0;i < params.length - 1;i++){
min = params[i];
for(int j = i + 1;j < params.length;j++){
if(min > params[j]){
min = params[j];
ref = j;
}
}
min = params[i];
params[i] = params[ref];
params[ref] = min;
}
System.out.println();
}
}
运行结果如下:
排序前的数据为:
1 9 5 2 7 4 3 8
排序后的数据为:
1 2 3 4 5 7 8 9
标签:.so ram test 选择 ref stat splay ade return
原文地址:https://www.cnblogs.com/ITBlock/p/10349373.html