一趟快速怕序的具体做法是:附设两个指针low和high,他们的初值分别为low和high,设枢轴记录的关键字为privotkey,则首先从high所指位置向前搜索找到第一个关键字小于pivotkey的记录和枢轴记录互相交换,然后从low所指向的位置起向后搜索,找到第一个关键字大于privotkey的记录和枢轴记录互相交换,重复这两步直至low==high位置.
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class 快速排序_1 {
public static void main(String[] args) throws InterruptedException {
int test[] = {15,23,56,7,13,52,20,7};
new 快速排序_1().qSort(test, 0, test.length-1);
for(int k:test) System.out.println(k);
}
public void qSort(int []array,int low,int high){
if(low
int privot=partition(array,low,high);
qSort(array,low,privot-1);
qSort(array,privot+1,high);
}
}
public int partition(int [] array,int low,int high){
/**
* 选择 low位置 作为曲轴(支点)
*/
int pivot=array[low];
int temp=0;
/**
* 如果 low
*/
while(low
/**
* 先从 high端 开始判断
*/
while(low=pivot) high--;
/**
* 进行 置换操作
*/
if(low
array[low]=array[high];
low++;
}
/**
* 从 low 端判断
*/
while(low
/**
* 进行 置换操作
*/
if(low
array[high]=array[low];
high--;
}
}
array[low]=pivot;
return low;
}
}
温馨提示:答案为网友推荐,仅供参考