import java.util.*;
public class SortArray
{
public static int maxNum = 1000;
//public static int maxNum = 100000;
//public static int maxNum = 10;
public static int[] randArray = new int[maxNum];
public static Random randGen = new Random(1239480);
public static long startTime;
public static long startTime2;
public static long endTime;
public static long endTime2;
public static long elapsedTime;
public static long elapsedTime2;
mergeSort(randArray, 0, randArray.length);
System.out.println("The merge sort algorithm took: " + elapsedTime
+ " ms");
quickSort(randArray, 0, randArray.length-1);
System.out.println("The quick sort algorithm took: " + elapsedTime2
+ " ms");
System.out.println("");
startTime = System.currentTimeMillis();
int firstHalf; // Size of the first half of the array
int secondHalf; // Size of the second half of the array
if (n > 1)
{
// Compute sizes of the two halves
firstHalf = n / 2;
secondHalf = n - firstHalf;
public static void merge(int[] rList, int first, int array1, int array2)
{
/**
* --------This method merges the two sorted halves---------
*
* numTempElements = number of elements copied from rList to temp
* numFirstElements = number copied from the first half of data
* numSecndElements = number copied from the second half of data
*/
// partition
do
{
while (randArray[i]<x) i++;
while (randArray[j]>x) j--;
if (i<=j)
{
h=randArray[i]; randArray[i]=randArray[j]; randArray[j]=h;
i++; j--;
}
} while (i<=j);
// recursion
if (low<j) quickSort(randArray, low, j);
if (i<hi) quickSort(randArray, i, hi);
endTime2 = System.currentTimeMillis();
elapsedTime2 = endTime2- startTime2;
} // end quickSort()