import java.util.Random;
import java.util.Arrays;
import javax.swing.JOptionPane;

public class SortComparisons {
	final static int billion = 1000000000;

	public static void main(String[] args) {
		Random generator = new Random();
		long t1;
		long t2;
		int size = Integer.parseInt(JOptionPane.showInputDialog("Enter the array size"));
		int[] Big = new int[size];
		for( int i = 0; i < size; i++ ) {
			Big[i] = generator.nextInt(billion);
		}
		
		// insertion sort on ints
		if( size <= 100000 )
		{
			int[] BigInsertion = new int[size];
			for(int i = 0; i < size; i++) BigInsertion[i] = Big[i];
			t1 = System.currentTimeMillis();
			Sorts.insertionSort(BigInsertion);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " ints with the insertion sort took " + (t2 - t1) + " milliseconds.");
		}

		// Shell's sort on ints
		{
			int[] BigShell = new int[size];
			for(int i = 0; i < size; i++) BigShell[i] = Big[i];
			t1 = System.currentTimeMillis();
			Sorts.shellSort(BigShell);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " ints with Shell's sort took " + (t2 - t1) + " milliseconds.");
		}

		// heap sort on ints
		{
			int[] BigHeap = new int[size];
			for(int i = 0; i < size; i++) BigHeap[i] = Big[i];
			t1 = System.currentTimeMillis();
			Sorts.heapSort(BigHeap);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " ints with the heap sort took " + (t2 - t1) + " milliseconds.");
		}
		
		// merge sort on ints
		{
			int[] BigMerge = new int[size];
			for(int i = 0; i < size; i++) BigMerge[i] = Big[i];
			t1 = System.currentTimeMillis();
			Sorts.mergeSort(BigMerge);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " ints with the merge sort took " + (t2 - t1) + " milliseconds.");
		}

		// quick sort on ints
		{
			int[] BigQuick = new int[size];
			for(int i = 0; i < size; i++) BigQuick[i] = Big[i];
			t1 = System.currentTimeMillis();
			Sorts.quickSort(BigQuick);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " ints with the quick sort took " + (t2 - t1) + " milliseconds.");
		}
		
		// Java sort on ints
		{
			int[] BigJava = new int[size];
			for(int i = 0; i < size; i++) BigJava[i] = Big[i];
			t1 = System.currentTimeMillis();
			Arrays.sort(BigJava);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " ints with the Java sort took " + (t2 - t1) + " milliseconds.");
		}

		Sorts s = new Sorts();
		
		// insertion sort with Integer
		if( size < 10000 )
		{
			Object[] ints = new Integer[size];
			for( int i = 0; i < size; i++ ) {
				ints[i] = new Integer(Big[i]);
			} // end for
			t1 = System.currentTimeMillis();
			s.insertionSort(ints);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " Integers with the insertion sort took " + (t2 - t1) + " milliseconds.");
		}

		// Shell's sort with Integer
		{
			Object[] ints = new Integer[size];
			for( int i = 0; i < size; i++ ) {
				ints[i] = new Integer(Big[i]);
			} // end for
			t1 = System.currentTimeMillis();
			s.shellSort(ints);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " Integers with the Shell's sort took " + (t2 - t1) + " milliseconds.");
		}

		// heap sort with Integer
		{
			Object[] ints = new Integer[size];
			for( int i = 0; i < size; i++ ) {
				ints[i] = new Integer(Big[i]);
			} // end for
			t1 = System.currentTimeMillis();
			s.heapSort(ints);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " Integers with the heap sort took " + (t2 - t1) + " milliseconds.");
		}

		// merge sort with Integer
		{
			Object[] ints = new Integer[size];
			for( int i = 0; i < size; i++ ) {
				ints[i] = new Integer(Big[i]);
			} // end for
			t1 = System.currentTimeMillis();
			s.mergeSort(ints);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " Integers with the merge sort took " + (t2 - t1) + " milliseconds.");
		}
		
		// quick sort with Integer
		{
			Object[] ints = new Integer[size];
			for( int i = 0; i < size; i++ ) {
				ints[i] = new Integer(Big[i]);
			} // end for
			t1 = System.currentTimeMillis();
			s.quickSort(ints);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " Integers with the quick sort took " + (t2 - t1) + " milliseconds.");
		}
		
		// Java sort with Integer
		{
			Object[] ints = new Integer[size];
			for( int i = 0; i < size; i++ ) {
				ints[i] = new Integer(Big[i]);
			} // end for
			t1 = System.currentTimeMillis();
			Arrays.sort(ints);
			t2 = System.currentTimeMillis();
			JOptionPane.showMessageDialog(null,"Sorting " + size + " Integers with the Java sort took " + (t2 - t1) + " milliseconds.");
		}
		
		System.exit(0);
	}

} // end SortComparisons

