package mysql;
/**
* Created by Zhangshunyu on 2017/8/19.
*/
public class test {
public static void main (String[] args) {
int[] testArray = {3,5,8,1,2,9,0,4};
quickSort(testArray, 0, testArray.length - 1);
for (int i : testArray) {
System.out.print(i);
}
}
public static void quickSort(int[] array, int low, int high) {
int lowTag = low;
int highTag = high;
int key = array[low];
while (lowTag < highTag) {
while (highTag > lowTag && array[highTag] > key) {
highTag--;
}
int tempSmall = array[highTag];
array[highTag] = array[lowTag];
array[lowTag] = tempSmall;
lowTag++;
while (lowTag < highTag && array[lowTag] < key) {
lowTag++;
}
int tempBig = array[lowTag];
array[lowTag] = array[highTag];
array[highTag] = tempBig;
highTag--;
}
if (low < lowTag) {
quickSort(array, low, lowTag - 1);
}
if (high > highTag) {
quickSort(array, highTag + 1, high);
}
}
}
网友评论