Skip to content
On this page

插入排序

Code

function insertSort(nums) {
  const n = nums.length;
  for (let i = 1; i < n; i++) {
    for (let j = i; j > 0 && nums[j] < nums[j - 1]; j--) {
      exchange(nums, j, j - 1);
    }
  }
}