title: Sorting an Array List using Merge Sort
body: <p>I am having trouble with converting my sorting class to sort objects with arraylists.  It is currently sorting objects, but I am having trouble converting it to sorting Arraylists.  Here is the code:</p>
  
  <pre><code>package Merge_Sort_Objects_ArrayList;
  import java.util.ArrayList;
  public class mergesort {
  
      /**
       * Merges two sorted portion of items array
       * pre: items[start.mid] is sorted.  items[mid+1.end] sorted.  start &lt;= mid &lt;= end
       * post: items[start.end] is sorted
       */
  
      private static void merge(ArrayList &lt;Comparable&gt; items, int start, int mid, int end){
              Comparable temp;
              int pos1 = start;
              int pos2 = mid + 1;
              int spot = start;
              ArrayList &lt;Comparable&gt; objectSort = items;
  
              while (!(pos1 &gt; mid &amp;&amp; pos2 &gt; end)){
                  if ((pos1 &gt; mid) || ((pos2 &lt;= end) &amp;&amp;(items[pos2].getRadius() &lt; items[pos1].getRadius()))){
                      temp[spot] = items[pos2];
                      pos2 +=1;
                  }else{
                      temp[spot] = items[pos1];
                      pos1 += 1;
                  }
                  spot += 1;
              }
              /* copy values from temp back to items */
  
              for (int i = start;  i &lt;= end; i++){
                  items[i] = temp[i];
              }
      }
  
      /**
       * mergesort items[start..end]
       * pre: start &gt; 0, end &gt; 0
       * post: items[start..end] is sorted low to high
       */
      public static void mergesort(ArrayList &lt;Comparable&gt; items, int start, int end){
          if (start &lt; end){
              int mid = (start + end) / 2;
              mergesort(items, start, mid);
              mergesort(items, mid + 1, end);
              merge(items, start, mid, end);
          }
      }
  }
  </code></pre>
  
  <p>now I have started to convert it, however I am stuck on this section right here:</p>
  
  <pre><code>  while (!(pos1 &gt; mid &amp;&amp; pos2 &gt; end)){
              if ((pos1 &gt; mid) || ((pos2 &lt;= end) &amp;&amp;(items[pos2].getRadius() &lt; items[pos1].getRadius()))){
                  temp[spot] = items[pos2];
                  pos2 +=1;
              }else{
                  temp[spot] = items[pos1];
                  pos1 += 1;
              }
              spot += 1;
          }
          /* copy values from temp back to items */
  
          for (int i = start;  i &lt;= end; i++){
              items[i] = temp[i];
          }
  </code></pre>
  
  <p>Thank you in advance!</p>