package labtwo.mergesort;

/**
 * Created by Ajay on 1/15/14.
 */
public class MergeSort {

    public static void mergeSort(int[] array, int[] temp, int p, int q) {
        if (p < q) {
            int r = Math.floorDiv((p + q), 2);
            mergeSort(array, temp, p, r);
            mergeSort(array, temp, (r + 1), q);
            merge(array, temp, p, r, q);
        }
    }

    private static void merge(int[] array, int[] temp, int p, int q, int r) {
        int i = p;
        int j = q + 1;
        for (int k = p; k <= r; k++) {
            temp[k] = array[k];
        }
        for (int k = p; k <= r; k++) {
            if (i > q) {
                array[k] = temp[j];
                j++;
            } else if (j > r) {
                array[k] = temp[i];
                i++;
            } else if (temp[j] < temp[i]) {
                array[k] = temp[j];
                j++;
            } else {
                array[k] = temp[i];
                i++;
            }
        }
    }
}

@@ -24,47 +24,8 @@
 t;%0A%0A
-/**%0A * Created by Ajay on 1/15/14.%0A */%0A
 publ
@@ -108,24 +108,29 @@
 mp, int 
-p
+low
 , int 
-q
+high
 ) %7B%0A    
@@ -141,13 +141,18 @@
 if (
-p %3C q
+low %3C high
 ) %7B%0A
@@ -171,34 +171,45 @@
 int 
-r = Math.floorDiv((p + q),
+mid = (int) Math.floor((low + high) /
  2);
@@ -244,20 +244,24 @@
 , temp, 
-p, r
+low, mid
 );%0A     
@@ -295,17 +295,22 @@
 p, (
-r
+mid
  + 1), 
-q
+high
 );%0A 
@@ -343,15 +343,22 @@
 mp, 
-p, r, q
+low, mid, high
 );%0A 
@@ -436,23 +436,30 @@
 int 
-p
+low
 , int 
-q
+high
 , int 
-r
+mid
 ) %7B%0A
@@ -474,17 +474,19 @@
 int i = 
-p
+low
 ;%0A      
@@ -495,17 +495,20 @@
 int j = 
-q
+high
  + 1;%0A  
@@ -522,33 +522,37 @@
 or (int k = 
-p
+low
 ; k %3C= 
-r
+mid
 ; k++) %7B%0A   
@@ -615,17 +615,21 @@
 k = 
-p
+low
 ; k %3C= 
-r
+mid
 ; k+
@@ -657,9 +657,12 @@
 i %3E 
-q
+high
 ) %7B%0A
@@ -745,17 +745,19 @@
 if (j %3E 
-r
+mid
 ) %7B%0A    
@@ -1020,8 +1020,10 @@
     %7D%0A%7D%0A
+%0A%0A

Update MergeSort.java