0
所以我正在寫一個程序,將使用快速排序字符串的自定義數組列表。 (我必須自定義編寫一個類的所有代碼)。但是,我不斷收到堆棧溢出錯誤,我不知道爲什麼。 (我是一個初學者,所以很容易)。Java堆棧與遞歸溢出
void quickSort() {
recursiveQuickSort(0, numElements-1);
}
// Recursive quicksort
public void recursiveQuickSort(int start, int end) {
// if size 1 or less, don't need to do anything
int pivotPosition = 0;
if (start <=1 || end <= 1) {
} else
pivotPosition =partition(start, end);
recursiveQuickSort(start, pivotPosition-1);
recursiveQuickSort(pivotPosition+1, end);
}
static int partition(int start, int end) {
int pivot = end;
end--;
while(true) {
while (true) {
if (end < start) {
break;
}
if (end < pivot) {
end = end;
break;
} else end --;
}
while(true) {
if (end < start) {
break;
}
if (start > pivot) {
start = start;
break;
} else start++;
}
if(end < start) {
break;
}
else
swap(start, end);
}
swap(end+1, pivot);
return end + 1;
}