package junit.test;
public class QuickSort2 {
public static int[] array = { 5,2,6,8,4,7,3};
//快速排序
void quick_sort(int s[], int index, int last)
{
int x = s[index];
for (int i2 = 0; i2 < s.length; i2++) {
System.out.print(s[i2]+" ");
}
System.out.println("-----------------------------");
if (index<last) {
int i = index, j = last;
while (i<=j) {
if (s[i]>s[j]) {
int x2 = s[i];
s[i]=s[j];
s[j]=x2;
}
i++;
j--;
}
quick_sort(s, index, --i);
quick_sort(s, ++i, last);
}
}
public static void main(String[] args) {
new QuickSort2().quick_sort(array, 0, array.length-1);
}
}
思想是,分,治,合,这是分割排序的例子,快速排序的变种,特点就是,两边同时进一格,而不是一边一边来。