动画
https://luanpeng.blog.csdn.net/article/details/78056408
var merge=function (a,b) {
let c = []
let i=0;
let j=0;
while(i<a.length && j<b.length){
a[i]<b[j]?c.push(a[i++]):c.push(b[j++])
}
if(i<a.length) c=c.concat(a.slice(i))
if(j<b.length) c=c.concat(b.slice(j))
return c;
}
var sort = function(arr) {
if(arr.length<2) return arr;
let mid = Math.floor(arr.length/2)
let left = arr.slice(0,mid)
let right = arr.slice(mid)
return merge(sort(left),sort(right))
}
网友评论