运行时错误线程“main”java中的异常。lang.Stackoverflowerr。我已经在Gfg上写了一个快速排序代码。需要得到清楚的解释
这是我写的快速排序代码,但我得到了一个运行时错误 我已经做了一次试运行,我没有发现任何类型的错误,但我得到了这个运行时错误
class Solution
{
static void quickSort(int arr[], int low, int high)
{
if(low<high){
int pivot = partition(arr, low, high);`enter code here`
quickSort(arr,low,pivot-1);
quickSort(arr,pivot+1,high);
}
}
static int partition(int arr[], int low, int high)
{
int pivot = arr[0];
while(low<high){
while(arr[low]<=pivot){
low++;
}
while(arr[high]>pivot){
high--;
}
if(low<high){
int temp = arr[high];
arr[high] = arr[low];
arr[low] = temp;
}
}
int temp = arr[high];
arr[high] = pivot;
pivot = temp;
return high;
}
}
共 (0) 个答案