Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: -1解决方法
public static int partition(int []arr,int left,int right) {
int pivotKey = arr[left];int pivotPointer = left;while(left<right) {
while(arr[right]>=pivotKey) {
right--;}while(arr[left]<=pivotKey) {
left++;}swap(arr,left,right);}swap(arr,pivotPointer,left);return left;}
这里报错了,是因为right–,left++没有限制
public static int partition(int []arr,int left,int right) {
int pivotKey = arr[left];int pivotPointer = left;while(left<right) {
while(left < right && arr[right]>=pivotKey) {
right--;}while(left < right && arr[left]<=pivotKey) {
left++;}swap(arr,left,right);}swap(arr,pivotPointer,left);return left;}
这样就有限制了。