该文章用来记录对快排的理解,方便回忆
function quickSort(arr, left, right) {//left和right代表所要进行对比区间var len = arr.length,partitionIndex,left = typeof left != 'number' ? 0 : left,right = typeof right != 'number' ? len - 1 : right;//设置初始首尾下标if (left
排序函数来自www.jianshu.com/p/1b4068ccd… ,对其中的快排做分析,原作者的各种排序算法罗列值得一看,并附有生动形象的图片,方便理解
附带另一种写法&#xff1a; var quicksort &#61; function (arr) {if (arr.length <&#61; 1) {return arr;}var pivotIndex &#61; Math.floor(arr.length / 2);//取一个基准值&#xff0c;用于做参考点&#xff08;不一定要用这个&#xff0c;像上面&#xff0c;以左侧做基准值&#xff09;var pivot &#61; arr.splice(pivotIndex, 1)[0];var left &#61; []; var right &#61; [];for (var i &#61; 0; i