public void mergeSort (int first, int last) { if (first < last) { int middle = (first + last) / 2; mergeSort(first,middle); mergeSort(middle+1,last); merge(first,middle,last); } } public void merge (int first, int middle, int last) { int [] temp = new int[last-first+1]; int first1 = first; int last1 = middle; int first2 = middle + 1; int last2 = last; int index = 0; while ((first1 <= last1) && (first2 <= last2)) { if (list[first1] < list[first2]) { temp[index] = list[first1]; first1++; } else { temp[index] = list[first2]; first2++; } index++; } while (first1 <= last1) { temp[index] = list[first1]; first1++; index++; } while (first2 <= last2) { temp[index] = list[first2]; first2++; index++; } int listIndex = first; for (index = 0; index < temp.length; index++) { list[listIndex] = temp[index]; listIndex++; } }