package edu.sort;
public class testtwo {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=0;
System.out.println(++a);
int[] array = { 12, 44, 88, 8, 6, 3, 2, 99 };
System.out.println("排序前:");
for (int i : array) {
System.out.print(i+",");
}
System.out.println();
QuickSort(array, 0, array.length-1);
//System.out.println("排序后:");
//for (int i : array) {
//System.out.print(i+",");
//}
}
public static void QuickSort(int[] array,int left,int right)
{
int last;
if (left>=right)
return;
int rand = (left+right)/2;
Swap(array, left, rand );
last = left ;
// System.out.println(last);
for (int i = left + 1; i <= right; i++)
{
if (array[i] < array[left])
Swap(array, ++last, i );
}
// for (int j : array) {
//System.out.print(j+",");
//}
System.out.println();
Swap(array, left, last);
QuickSort(array, left, last-1 );
QuickSort(array, last + 1, right );
}
private static void Swap(int[] a,int i,int j)
{
System.out.println("left:"+i+"right:"+j);
int temp;
temp = a[i];
a[i] = a[j];
a[j] = temp;
for (int k : a) {
System.out.print(k+",");
}
}
}
|
|