title: 3 Way Quicksort: Exception in thread "main" java.lang.StackOverflowError
body: <p>While implementing 3-way-quicksort I've encountered a error message that I don't know how to fix. This is the traceback for the error in console:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.StackOverflowError
      at projects.Main.quickSortByRecursion(Main.java:45)
      at projects.Main.quickSortByRecursion(Main.java:47)
      at projects.Main.quickSortByRecursion(Main.java:47)
      at projects.Main.quickSortByRecursion(Main.java:47)
  </code></pre>
  <p>This goes for many more lines, 200 or so. Basically I'm just trying to implement a 3-way-quicksort. Here's my code:</p>
  <pre><code>static void partition(int[] intArray, int low, int high, int i, int j)    {
  
      if(high - low &lt;= 1) {
          if(intArray[high] &lt; intArray[low]) {
              swapElements(intArray, high, low);
          }
      }   else    {
          i = low;
          j = high;
          return;
      }
      int midpoint = low;
      int pivot = intArray[high];
      while (midpoint &lt;= high)    {
          if(intArray[midpoint] &lt; pivot)  {
              swapElements(intArray, low + 1, midpoint + 1);
          }
          else if(intArray[midpoint] == pivot)    {
              midpoint += 1;
          }
          else if(intArray[midpoint] &gt; pivot) {
              swapElements(intArray, midpoint, high - 1);
          }
          i = low - 1;
          j = midpoint;
      }
  }
  
  static void quickSort(int intArray[])   {
      quickSortByRecursion(intArray, 0, intArray.length - 1);
  }
  
  static void quickSortByRecursion(int intArray[], int low, int high)   {
      if(low &gt;= high)  {
          return;
      }
      int i = 0;
      int j = 0;
  
      partition(intArray, low, high, i, j);
      quickSortByRecursion(intArray, low, i);
      quickSortByRecursion(intArray, j, high);
  }
  
  static void swapElements(int intArray[], int low, int high) {
      int temporaryValue = intArray[low];
      intArray[low] = intArray[high];
      intArray[high] = temporaryValue;
  }
  
  public static void main(String[] args) {
      int[] intArray = { 1, 3, 2, 4, 7, 9, 8, 5, 4, 6 };
  
      for(int i : intArray)   {
          System.out.println(i);
      }
      quickSort(intArray);
  
      for(int i: intArray)    {
          System.out.println(i);
      }
  }
  </code></pre>
  <p>}</p>
  <p>I was also implementing other quicksorts, one by recursion second one with insertionSort inside and I haven't encountered with this issue yet. I've looked for similar answers but only thing I found was a incorrect usage of int/long parameters. Any ideas?</p>