我是编程的绝对初学者,我试图实现一个关于YouTube视频的QuickSort功能,该视频只有一个理论上的解释,我试图实现相同的功能。但是我得到java.lang.ArrayIndexOutOfBoundsException
。这是我的功能:
static void sort(int left, int right){
int mid = right - ((right - left)/2);
boolean proceedleft = false;
boolean proceedright = false;
for (int i = left; i <= right; i++){
if(random[i] < random[mid] && i > mid){
int temp = random[i];
for(int s = i; s < mid; s++){
random[s] = random[s+1];
}
random[mid] = temp;
mid--;
proceedleft = true;
}
if(random[i] > random[mid] && i < mid){
int temp = random[i];
for(int s = i; s < mid; s--){
random[s] = random[s-1];
}
random[mid] = temp;
mid++;
proceedright = true;
}
}
if(proceedleft == true){
sort(left, mid - 1);
}
if(proceedright == true){
sort(mid + 1, right);
}
}
我犯了什么错误? 谢谢!