- var arr = [11,45,6,23,10];
- var quickSort = function(a){
- var len = a.length;
- if(len<1){
- return a;
- }
- function sort(low,height){
- var pivot = a[low];
- var i=low,j=height,t;
- if(i>j){
- return false;
- }
- while(i!=j){
- while(a[j]>=pivot&&i<j){
- j--;
- }
- while(pivot>=a[i]&&i<j){
- i++;
- }
- if(i<j){
- t = a[i];
- a[i] = a[j];
- a[j] = t;
- }
- }
- a[low] = a[i];
- a[i] = pivot;
- sort(low,i-1);
- sort(i+1,height);
- }
- sort(0,len-1);
- return a;
- }
- console.log(quickSort(arr));
- //该片段来自于http://www.codesnippet.cn/detail/1609201513697.html
来源: http://www.codesnippet.cn/detail/1609201513697.html