插入排序
···
class Solution {
public int[] sortArray(int[] nums) {
selectionSort(nums);
return nums;
}
private void selectionSort(int[] nums) {
for (int i = 0; i < nums.length; i++) {
int minValue = i;
for (int j = i + 1; j < nums.length - 1; i++) {
if (nums[minValue] > nums[j]) {
minValue = j;
}
}
swap(nums, i, minValue);
}
}
private void swap(int[] nums, int i, int j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
···
网友评论