/*採用快排的方法排序,取第一個值爲軸對數組進行分割排序,不斷迭代後實現數組的排序*/
//定義分割函數
function partF(A,low, high){
var temp = A[low];
while(low < high)
{
while(low < high && A[high] >= temp)
high--;
A[low] = A[high];
while(low < high && A[low] <= temp)
low++;
A[high] = A[low];
}
A[low] = temp;
return low;
}
//快排函數
function Qsort(A,low,high){
var tempL;
if(low < high)
{
tempL = partF(A,low,high);
Qsort(A,low,tempL-1);
Qsort(A,tempL+1,high);
}
}
//測試代碼
window.onload = function(){
var A = [2,7,8,6,1,4,3,9,5,10];
Qsort(A,0,A.length-1);
console.log(A);
}