/**
*
* @author think
* 快速排序
* 时间复杂度o(n*logn);
*/
public class QuickSort {
public static int exe(int[]a,int start,int end)
{
int base = a[end];//取末尾元素为基准
while(start < end)
{
while(start < end && a[start] <= base)//向右排查
start++;
if(start < end)//将比基准小的元素放在左侧
{
int temp = a[start];
a[start] = a[end];
a[end] = temp;
end--;
}
while(start < end && a[end] >= base)//向左排查
end--;
if(start < end)//将比基准大的元素放在右侧
{
int temp = a[start];
a[start] = a[end];
a[end] = temp;
start++;
}
}
return end;//返回分界
}
public static void quickSort(int[]a,int start,int end)
{
if(start > end)
return;
else
{
int position = exe(a,start,end);
quickSort(a,start,position-1);
quickSort(a,position+1,end);
}
}
public static void main(String[] args) {
int[] array=new int[]{1,2,3,30,7,8,44,10,19,16};
quickSort(array,0,array.length-1);
for(int i=0;i
算法思想就是在一个混乱序列中找到一个基准b,进行一趟遍历,将比基准b小的元素放在其左侧,反之放在其右侧。再以b为分界将原序列分为两个子序列,分别找到各自新的基准进行递归操作,递归的结束标志就是细分的数组仅含一个元素,此时就完成了对整个序列的排序。