使用quickSort时得到stackoverflower错误,我可以增加堆栈和堆吗?

Eng*_*uad 2 java stack-overflow quicksort

我可以在java中增加堆栈和堆吗?我正在使用BlueJ.

========

编辑:

这是代码:

// ***** Quick-Sort Method *****

public static void quickSort(int[] data, int first, int n)
{
    int p, n1, n2;
    if(n > 1)
    {
        p = partition(data, first, n);
        n1 = p - first;
        n2 = n - n1 - 1;
        quickSort(data, first, n1);
        quickSort(data, p+1, n2);
    }
}

// ***** PRIVATE HELPER FUNCTIONS *****

public static void quickSort(int[] data)
{
    quickSort(data, 0, data.length);
}

private static int partition(int[] A, int first, int n )
{
    int right = first + n - 1;
    int ls = first;
    int pivot = A[first];
    for(int i = first+1; i <= right; i++)
    {
        if(A[i] <= pivot)
        // Move items smaller than pivot only, to location that would be at left of pivot
        {
            ls++;
            swap(A, i, ls);
        }
    }
    swap(A, first, ls);
    return ls;
}

private static void swap(int[] data, int pos1, int pos2)
{
    int temp = data[pos1];
    data[pos1] = data[pos2];
    data[pos2] = temp;
}
Run Code Online (Sandbox Code Playgroud)

Hyp*_*eus 6

试图通过溢出来增加堆栈大小,就像购买更多的垃圾箱,当你的垃圾箱已满而不是把它带到垃圾场.

最有可能的是你进入无休止的递归.你能发贴你的代码吗?