title: Void merge sort method java
body: <p>So, my computer science teacher has told me to make every method here void, except for copyPartArray. I have no idea how to do this, when I try, the sort simply fails.</p>
  
  <pre><code>public static ArrayList&lt;String&gt; mergeSortHelper(ArrayList&lt;String&gt; a) {
      int mid = a.size() / 2 - 1;
      if (a.size() &lt;= 1)
          return a;
      return merge(mergeSortHelper(copyPartArray(a, 0, mid)),
              mergeSortHelper(copyPartArray(a, mid + 1, a.size() - 1)));
  }
  
  public static void mergeSort(ArrayList&lt;String&gt; a) {
      ArrayList&lt;String&gt; x = mergeSortHelper(a);
      for (int i = 0; i &lt; a.size(); i++) {
          a.set(i, x.get(i));
      }
  }   
      public static ArrayList&lt;String&gt; merge(ArrayList&lt;String&gt; a,
          ArrayList&lt;String&gt; b) {
      ArrayList&lt;String&gt; x = new ArrayList&lt;String&gt;(a.size() + b.size());
      int aCount = 0;
      int bCount = 0;
      for (int i = 0; i &lt; a.size() + b.size(); i++) {
          if (aCount &gt; a.size() - 1) {
              for (int j = bCount; j &lt; b.size(); j++) {
                  x.add(b.get(j));
              }
              break;
          }
          if (bCount &gt; b.size() - 1) {
              for (int j = aCount; j &lt; a.size(); j++) {
                  x.add(a.get(j));
              }
              break;
          }
          if ((a.get(aCount)).compareTo(b.get(bCount)) &lt; 0) {
              x.add(a.get(aCount));
              aCount++;
          } else {
              x.add(b.get(bCount));
              bCount++;
          }
      }
      return x;
  }
  
      public static ArrayList&lt;String&gt; copyPartArray(ArrayList&lt;String&gt; a, int s,
          int e) {
      ArrayList&lt;String&gt; x = new ArrayList&lt;String&gt;();
      for (int i = s; i &lt;= e; i++) {
          x.add(a.get(i));
      }
      return x;
  </code></pre>
  
  <p>I have tried to change my mergeSort to:</p>
  
  <pre><code>    public static void mergeSort(ArrayList&lt;String&gt; a) {
      int mid = a.size() / 2 - 1;
      if (a.size() &lt;= 1)
          return;
      mergeSort(copyPartArray(a, 0, mid));
      mergeSort(copyPartArray(a, mid + 1, a.size() - 1));
      merge(a, copyPartArray(a, 0, mid),
              copyPartArray(a, mid + 1, a.size() - 1));
  }
  </code></pre>
  
  <p>and get rid of the mergeSortHelper all together.</p>
  
  <p>Now I have:</p>
  
  <pre><code>    public static void mergeSort(ArrayList&lt;String&gt; a, int start, int end) {
      int mid = (start + end) / 2;
      if (a.size() &lt;= 1)
          return;
      mergeSort(a, start, mid);
      mergeSort(a, mid + 1, end);
  </code></pre>
  
  <p>how would I incorporate my merge method into this?</p>