/** * @param args the command line arguments */ public static void main(String[] args) { // Show a sample random array does get sorted by merge sort SortableQueue Q = new SortableQueue(10); out.println("Before merge sorting"); out.println(Q); mergeSort(Q); out.println("After merge sorting"); out.println(Q); // Show a sample random array does get sorted by selection sort Q = new SortableQueue(10); out.println("Before selection sorting"); out.println(Q); Q = selectSort(Q); out.println("After selection sorting"); out.println(Q); // TODO: Add code to collect and display timing data // for queues of various sizes using merge sort // and using selection sort } // end main static void mergeSort(SortableQueue Q) { // out.println("sorting: " + Q); if (!Q.isSorted()) { SortableQueue Q1 = new SortableQueue(), Q2 = new SortableQueue(); Q.split(Q1, Q2); // out.println("first split: " + Q1); // out.println("second split: " + Q2); mergeSort(Q1); mergeSort(Q2); // out.println("Merging " + Q1 + " and " + Q2); Q.merge(Q1, Q2); // out.println("After merge: " + Q); } // end if } // end mergeSort static SortableQueue selectSort(SortableQueue Q) { // declare a new Sortable queue Q2 SortableQueue Q2 = new SortableQueue(); // repeatedly remove the minimum from Q and add that value to Q2 until Q is empty return Q2; } // end selectSort