0

So, I wrote a program for quicksort and when I input a large array size it gives me a StackOverflowError for quickSort_typeA, however, works completely fine for small size like 10000. Below is my code.

public static int partition_a(int[] a, int left, int right) 
{
        int pivot = a[left];
        while(left<=right) {
            while(a[left] < pivot)
                left++;
            while(a[right] > pivot)
                right--;
            if(left<=right) {
                int tmp = a[left];
                a[left] = a[right];
                a[right] = tmp;
                left++;
                right--;
            }
        }
        return left;
    }
    public static void quickSort_typeA(int[] a, int i, int j) {
       int idx = partition_a(a, i, j);
       if(i < idx-1) {
           quickSort_typeA(a, i, idx-1);
        }
       if(j > idx) {
           quickSort_typeA(a, idx, j);
        }
    }
Vishal Rana
  • 43
  • 1
  • 7
  • I get it. But I am not able to understand what mistake and where am I doing it. – Vishal Rana Oct 24 '20 at 20:39
  • So I figured out that the issue is with the stack size. I just read that "-Xss" can be used to set thread stack size. What exactly is it and how do I use it? – Vishal Rana Oct 24 '20 at 21:27
  • 1
    If you have figured it out and have a separate question, please ask your second question in a new post (after researching it, of course). – rajah9 Oct 25 '20 at 11:32

0 Answers0