@XQF
2018-03-07T22:53:23.000000Z
字数 473
阅读 609
数据结构与算法
选择排序是每次选一个基准数和后面的数进行比较,选出这一轮中包括基准数在内的最值。每一轮一次。
public class Solution {
public int[] selectSort(int[] nums) {
if(nums.length()==0||nums==null){
return null;
}
for (int i = 0; i < nums.length-1; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[i] > nums[j]) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
return nums;
}
public static void main(String[] args) {
Solution solution = new Solution();
int[] nums = {1, 2, 55, 6, 3, 2, 4, 5, 6, 8, 9, 0};
System.out.println(Arrays.toString(solution.selectSort(nums)));
}
}