let a = [1,43,3,3213,12,12,3,2,1,212,32]
// 插入排序
// function insertSort(arr){
// if(arr.length<=1){return arr}
// for(let i=0;i<arr.length;i++){
// let temp = arr[i] //当前遍历的值
// for(var j=i;j>0;j--){
// if(temp>arr[j-1]){
// break;
// }
// arr[j] = arr[j-1];
// }
// arr[j] = temp
// }
// return arr;
// }
// console.log( insertSort(a) )
// 解析:遍历当前的值 挨个和前面的比较,如果比前面大,直接跳出循环,反之把当前的值和前面的数对调位子
// 快速排序
// function quickSort(arr){
// let len = arr.length;
// if(len<=1){return arr};
// let left = [];
// let right = [];
// let index = Math.floor(len/2);
// let provit = arr.splice(index,1);
// console.log(provit)
// for (let x of arr){
// if(x<provit){
// left.push(x)
// }else{
// right.push(x)
// }
// }
// return quickSort(left).concat(provit,quickSort(right))
// }
// console.log( quickSort(a) )
// 解析:截取数组中间的数作为比较的基数,循环每个数和基数比较,创建两个空数组(left,right),小于基数的值全部放到left数组,大于基数的值全部放到right数组,然后递归left和right数组,
// 返回递归的left数组+基数+right数组。
// 选择排序
// function selectSort(arr){
// let minIndex;
// let tepm;
// for(let i=0;i<arr.length;i++){
// minIndex = i;
// for(let j=i+1;j<arr.length;j++){
// if(arr[j]<arr[minIndex]){
// //记录最小数的位子
// minIndex = j;
// }
// }
// temp = arr[minIndex];
// arr[minIndex] = arr[i]
// arr[i] = temp
// console.log(`第${i}轮排序后的结果${arr}`)
// }
// console.log("最后结果",arr)
// }
// selectSort(a)
// 解析:每一轮都选择找到最小的数放到最前面(下标i的位置)
// 冒泡排序
// function mpSort(arr){
// let temp;
// for(let i=0;i<arr.length;i++){
// for(let j=0;j<arr.length-i-1;j++){
// if(arr[j]>arr[j+1]){
// temp = arr[j];
// arr[j] = arr[j+1]
// arr[j+1] = temp
// }
// }
// }
// console.log(arr)
// }
// mpSort(a)
// 解析:每一轮把最大的数放到最后面