1.冒泡排序
var arr=[3,1,4,5,6,7,2,8];
function b(arr){
for(var i=0 ;i<arr.length -1;i++){
for(var j=0;j<arr.length-1-i;j++){
if(arr[j+1] < arr[j]){
var temp = arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp
}
}
}
return arr;
}
console.log(b(arr))
2.插入排序
var arr = [3,4,1,2,5,8,7,6];
function c(arr){
if(arr.length == 0){
return [];
}
var to = Math.floor(arr.length/2);
var d = arr.splice(to,1);
var l =[];
var r =[];
for (var i =0;i<arr.length; i++){
if(arr[i]<c){
l.push(arr[i]);
}else{
r.push(arr[i])
}
}
return c(l).concat(d,c(r));
}
console.log(c(arr))