private List<T> merge(List<T> leftList, List<T> rightList) {
    // Create the list that will contain the result (i.e., merge) of the two lists.
    List<T> mergedList = new ArrayList<T>();

    // As long as either the left or the right list has items remaining in it that have not been
    // merged, continue removing the elements in order and building up the merged list.
    while (leftList.size() > 0 || rightList.size() > 0) {
      // Case 1: Both lists have elements remaining.
      if (leftList.size() > 0 && rightList.size() > 0) {
        if (leftList.get(0).compareTo(rightList.get(0)) < 0) {
          // Left list contains next smallest element, so remove it and add it to the merged list.
          mergedList.add(leftList.remove(0));
        } else {
          // Right list contains next smallest element, so remove it and add it to the merged list.
          mergedList.add(rightList.remove(0));
        }
        continue;
      }
      
      // Case 2: Only the left list has elements remaining (we would not get to this point
      // in the code if the rightList.size() > 0), so the next smallest elements must be in the
      // left list.
      if (leftList.size() > 0) {
        // Remove the next element in the left list, which will be the next smallest element, and
        // add it to the merged list.
        mergedList.add(leftList.remove(0));
        continue;
      }
      
      // Case 3: Only the right list has elements remaining
      if (rightList.size() > 0) {
        // Remove the next element in the right list, which will be the next smallest element, and
        // add it to the merged list.
        mergedList.add(rightList.remove(0));
        continue;
      }
    }
    return mergedList;
  }