# java中的快速排序

public static int partio1(int []array,int low,int high ){
int tmp = array[low];
while(low<high){

while(low<high&& array[high]>=tmp){
--high;
}
if(low >=high){
break;
}else{
array[low] = array[high];
}
while(low<high&&array[low]<=tmp){
++low;
}
if(low>=high){
break;
}else{
array[high] =array[low];
}
}
array[low] = tmp;
return low;
}
public static void Quick(int array[],int start,int end){
int par = partio1(array,start,end);
if(par > start+1){
Quick(array,0,par);
}
if(par <end-1){
Quick(array,par+1,array.length-1);
}
}
public static void Quicksort(int array[]){
Quick(array,0,array.length-1);
}

0到4是基准左侧的下标范围，6到8是基准右侧的下标范围，然后让8和6出栈，对这

public static int partion(int[] array,int low,int high){
int point = array[low];
while(low < high){
while(low < high && array[high] >= point){
high--;
}
if(low >= high){
break;
}else{
array[low] = array[high];
}

while(low < high && array[low] <= point){
low++;
}
if(low >= high){
break;
}else{
array[high] = array[low];
}
}
array[low] = point;
return low;
}
public static void Quicks(int[] array){
int[] stack = new int[array.length];
int top = 0;
int low = 0;
int high = array.length-1;
int par = partion(array,low,high);
//入栈
if(par > low+1){
stack[top++] = low;
stack[top++] = par-1;
}

if(par < high-1){
stack[top++] = par+1;
stack[top++] = high;
}

//出栈
while(top > 0){
high = stack[--top];
low = stack[--top];

par = partion(array,low,high);
if(par > low+1){
stack[top++] = low;
stack[top++] = par-1;
}
if(par < high-1){
stack[top++] = par+1;
stack[top++] = high;
}
}
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120