各个排序的比较
冒泡排序
export default (arr) => { // 冒泡排序 for (let i = arr.length - 1, tmp; i > 0; i--) { for (let j = 0; j < i; j++) { tmp = arr[j] if (tmp > arr[j + 1]) { arr[j] = arr[j + 1] arr[j + 1] = tmp } } } return arr }
选择排序
export default (arr) => { // 选择排序 for (let i = 0, len = arr.length, min; i < len; i++) { min = arr[i] for (let j = i + 1; j < len; j++) { if (arr[j] < min) { let c = min min = arr[j] arr[j] = c } } arr[i] = min } return arr }
来源:https://www.cnblogs.com/ygjzs/p/12234405.html