由于堆栈溢出,我的程序无法编译。
问题在快速排序类的第206行。由于这是我学习java的第二门课程,我有点纠结于下一步该去哪里。任何帮助都将不胜感激。我将发布一个片段和一个到github repo的链接。
https://github.com/das1tmane/sort-comparison
谢谢。
public class QuickSort
{
/*
* Select the first item of the partition as the pivot. Treat
* partitions of size one and two as stopping cases.
*/
public int firstPartition(int arr[], int low, int high)
{
int pivot = arr[low];
int i = (high+1); // index of larger element
for (int j = high; j > low; j--)
{
// If current element is smaller than or
// equal to pivot
if (arr[j] >= pivot)
{
i--;
// swap arr[i] and arr[j]
int temp = arr[i];
arr[j] = temp;
}
}
// swap arr[i-1] and arr[low] (or *pivot*)
int temp = arr[i - 1];
arr[low] = temp;
return i-1;
}
public void sort(int arr[], int low, int high, int sortKind)
{
// QuickSort type 1; Pivot at first element,
if (low < high && sortKind == 0)
{
int pi = firstPartition(arr, low, high);
// Recursively sort elements before
// partition and after partition
sort(arr, low, pi - 1, 0);
sort(arr, pi + 1, low, 0);
}
// Quicksort type 2: stop at partitions of 100, then do
// insertion sort ```
暂无答案!
目前还没有任何答案,快来回答吧!