public void quickSort(int[] array, int begin, int end) {
if (begin >= 0 && begin < end && end <= array.length) {
int index = partition(array, begin, end);
quickSort(array, begin, index - 1);
quickSort(array, index + 1, end);
}
}
public int partition(int[] arry, int begin, int end) {
int i = begin - 1;
for (int j = begin; j < end - 1; ++j) {
if (arry[j] < arry[end - 1]) {
++i;
int temp = arry[i];
arry[i] = arry[j];
arry[j] = temp;
}
}
++i;
int temp = arry[i];
arry[i] = arry[end - 1];
arry[end - 1] = temp;
return i;
}
quickSort
最新推荐文章于 2024-05-14 10:51:55 发布