package learn.java;
public class QuickSort {
/**
* @param args
*/
public static void main(String[] args) {
int[] pendingSort={10,13,2,1,20,39,45,32,3,5,6,86,9,100,99,45,65,65,23};
int left=0;
int right=pendingSort.length-1;
int[] result=sort(pendingSort,left,right);
for(int index=0;index<result.length-2;index++){
System.out.print(result[index]+",");
}
System.out.print(result[result.length-1]);
}
private static int[] sort(int[] pendingSort, int left, int right)
{
if(left<right)
{
int temp=pendingSort[right];
int p=left;
int q=right;
while(p<q)
{
while(pendingSort[p]<=temp&&p<q)
{
p++;
}
pendingSort[q]=pendingSort[p];
while(pendingSort[q]>=temp&&q>p)
{
q--;
}
pendingSort[p] = pendingSort[q];
}
int mindle=p;
pendingSort[q]=temp;
sort(pendingSort,left,mindle-1);
sort(pendingSort,mindle+1,right);
}
return pendingSort;
}
}
时间复杂度 N O(logN) 空间复杂度logN,请参照视频http://v.youku.com/v_show/id_XNzQwNTAxMjA=.html