标签:
全排序列
function swap(array,a,b){ var m=array[a]; array[a]=array[b]; array[b]=m; } function full_sort(array,from,to){ if(from==to){ console.log(array); return; }else{ for(var i=from;i<to;i++){ swap(array,from,i); full_sort(array,from+1,to); swap(array,from,i); } } }
快速排序
function quicksort(array) { if (array.length <= 1) return array var pivotIndex = 0; var pivot = array[0]; var left = []; var right = []; for (var i = 1; i < array.length; i++) { if (array[i] > pivot) { right.push(array[i]) } else { left.push(array[i]); } } return quicksort(left).concat([pivot], quicksort(right)); }
标签:
原文地址:http://www.cnblogs.com/dubaokun/p/5239450.html