diff --git a/a2/src/edu/wmich/cs3310/a2/Controller.java b/a2/src/edu/wmich/cs3310/a2/Controller.java index 91d5dccf34aa1597a189f5cf9f7483c933ff35c1..00beab2a526e4378e92d6f599e7ae42e1e402744 100644 --- a/a2/src/edu/wmich/cs3310/a2/Controller.java +++ b/a2/src/edu/wmich/cs3310/a2/Controller.java @@ -1,6 +1,7 @@ package edu.wmich.cs3310.a2; import java.util.Arrays; +import java.util.Date; import java.util.Scanner; import java.util.HashMap; import java.util.Map; @@ -19,6 +20,16 @@ public class Controller { //region Variables private int charNumber; + private long bubbleArrayTime; + private long bubbleListTime; + private long selectArrayTime; + private long selectListTime; + private long mergeArrayTime; + private long mergeListTime; + private long insertArrayTime; + private long insertListTime; + private long bInsertArrayTime; + private long bInsertListTime; private String nameString; private boolean showStabilityNumbers; private Random random = new Random(); @@ -30,6 +41,7 @@ public class Controller { private char[] bInsertArray; private Map<String, int[]> sortingDictionary; private Map<String, int[]> stabilityDictionary; + private ComputeTime computeTime = new ComputeTime(); private LinkedQueue bubbleList = new LinkedQueue(); private LinkedQueue selectList = new LinkedQueue(); private LinkedQueue mergeList = new LinkedQueue(); @@ -79,6 +91,7 @@ public class Controller { SortAllDataStructures(); System.out.println("Post-Sorting Values: "); PrintAllDataStructures(); + PrintTimeValues(); } //endregion Constructors @@ -253,17 +266,48 @@ public class Controller { * Calls sorting on all available data structures. */ protected void SortAllDataStructures() { + Date startDate; //System.out.println("Sorting..."); + + // Bubble sorts. + startDate = new Date(); ArrayBubbleSort(); + bubbleArrayTime = computeTime.GetTimeLapse(startDate); + startDate = new Date(); ListBubbleSort(); + bubbleListTime = computeTime.GetTimeLapse(startDate); + + // Selection sorts. + startDate = new Date(); ArraySelectionSort(); + selectArrayTime = computeTime.GetTimeLapse(startDate); + startDate = new Date(); ListSelectionSort(); + selectListTime = computeTime.GetTimeLapse(startDate); + + // Merge sorts. + startDate = new Date(); ArrayMergeSort(0, (charNumber - 1)); + mergeArrayTime = computeTime.GetTimeLapse(startDate); + startDate = new Date(); mergeList = ListMergeSort(mergeList,0, (charNumber - 1)); + mergeListTime = computeTime.GetTimeLapse(startDate); + + // Insertion Sorts. + startDate = new Date(); ArrayInsertionSort(); + insertArrayTime = computeTime.GetTimeLapse(startDate); + startDate = new Date(); ListInsertionSort(); + insertListTime = computeTime.GetTimeLapse(startDate); + + // Binary Insertion sorts. + startDate = new Date(); ArrayBinaryInsertionSort(); + bInsertArrayTime = computeTime.GetTimeLapse(startDate); + startDate = new Date(); ListBinaryInsertionSort(); + bInsertListTime = computeTime.GetTimeLapse(startDate); } @@ -1023,6 +1067,49 @@ public class Controller { System.out.println(); } + + /** + * Prints out time value data for all sorts. + */ + protected void PrintTimeValues() { + long tempLong; + System.out.println(); + System.out.print("Bubble Array Time: "); + computeTime.PrintTime(bubbleArrayTime); + System.out.print("Bubble List Time: "); + computeTime.PrintTime(bubbleListTime); + + System.out.println(); + System.out.print("Selection Array Time: "); + computeTime.PrintTime(selectArrayTime); + System.out.print("Selection List Time: "); + computeTime.PrintTime(selectListTime); + + System.out.println(); + System.out.print("Merge Array Time: "); + computeTime.PrintTime(mergeArrayTime); + System.out.print("Merge List Time: "); + computeTime.PrintTime(mergeListTime); + + System.out.println(); + System.out.print("Insertion Array Time: "); + computeTime.PrintTime(insertArrayTime); + System.out.print("Insertion List Time: "); + computeTime.PrintTime(insertListTime); + + System.out.println(); + System.out.print("Binary Insertion Array Time: "); + computeTime.PrintTime(bInsertArrayTime); + System.out.print("Binary Insertion List Time: "); + computeTime.PrintTime(bInsertListTime); + + System.out.println(); + System.out.print("Overall Time: "); + tempLong = bubbleArrayTime + bubbleListTime + selectArrayTime + selectListTime + mergeArrayTime + mergeListTime + + insertArrayTime + insertListTime + bInsertArrayTime + bInsertListTime; + computeTime.PrintTime(tempLong); + } + //endregion User Interface Methods