首页 > 代码库 > jszs 快速排序

jszs 快速排序

<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><script>window.onload = function (){        function quicksort(arr)    {        if(arr.length<=1)        {            return arr;        }                var num = arr.length/2;        var numvalue = http://www.mamicode.com/arr.splice(num,1);        var left = [];        var right = [];        for(var i = 0; i < arr.length; i++)        {            if(arr[i]<numvalue)            {                left.push(arr[i]);            }            else            {                right.push(arr[i]);            }        }                return quicksort(left).concat([numvalue],quicksort(right));    }    alert(quicksort([12,5,37,6,22,40]));    }</script></head><body></body></html>

 

jszs 快速排序