虽然简单,但是编成后,心情是无法用语言来形容的:)
public class Lx737
{
public static void main(String[] args)
{
//int[] array={6,7,2,4,1,5};
//int[] array={35,12,23,45,67,33,21,89,99,21,12};
int[] array={1,2,3,4,5,6,7,8,9,0};
partition(array,0,array.length-1);
for(int i=0;i<array.length;i++)
{
System.out.println(array[i]);
}
}
public static void partition(int[] array,int begin,int end)
{
int low,high,index;
if(begin>end)
return;
index=array[begin];
low=begin;
high=end;
while(low<high)
{
while(index<array[high]&&low<high)
{
high--;
}
array[low++]=array[high];//先用low原先的值,然后加1
while(index>array[low]&&low<high)
{
low++;
}
array[high--]=array[low];
}
array[low]=index;
partition(array,begin,low-1);
partition(array,high+1,array.length-1);
}
}