title: Modifying mergesort program to support searching subarrays
body: <p>I have been stuck for about a week now trying to modify a mergesort program to support searching subarrays. The user would give an unsorted list of words as command-line arguments along with the starting and ending index of the subarray that should be sorted. The program should print out a list where the strings between the given indexes are sorted alphabetically.</p>
  <p><strong>Two sample test cases could be:-</strong></p>
  <p><strong>Case 1:-</strong></p>
  <pre><code>command:- java MergeSort 2 4 toy apply sand bay cat dog fish
  
  Expected Output:- toy apply bay cat sand dog fish
  </code></pre>
  <p><strong>Case 2:-</strong></p>
  <pre><code>command:- java MergeSort 0 3 was had him and you his the but
  
  Expected Output:- and had him was you his the but 
  </code></pre>
  <p>The code that I am trying to modify is below:</p>
  <pre><code>public class MergeSort {
      public static void sort(Comparable[] a)
      {
          Comparable [] aux = new Comparable[a.length];
          sort(a, aux, 0, a.length);
      }
      
      private static void sort(Comparable[] a, Comparable[] aux, int lo, int hi)
      { 
      if (hi - lo &lt;= 1) return;
      int mid = lo + (hi-lo)/2;
      sort(a, aux, lo, mid);
      sort(a, aux, mid, hi);
      int i = lo, j = mid;
      for (int k = lo; k &lt; hi; k++)
          if (i == mid) aux[k] = a[j++];
          else if (j == hi) aux[k] = a[i++];
          else if (a[j].compareTo(a[i]) &lt; 0) aux[k] = a[j++];
          else                               aux[k] = a[i++];
          
      for (int k = lo; k &lt; hi; k++)
          a[k] = aux[k];
      }
      public static void main (String [] args) {
          
          String[] a = StdIn.readAllStrings();
          sort(a);
          for (int i = 0; i &lt; a.length; i++)
              StdOut.print(a[i] + &quot; &quot;);
          StdOut.println();
          
      }
  }
  </code></pre>
  <p>Any help would be greatly appreciated! I am new to Java and have only been in the programming world for about 2 months now!</p>