import java.util.Scanner; /** Driver.java - Read a list of integers from standard input. That will * be our array for testing and timing 4 sorting algorithms. Assume that * all the numbers will be on the first and only line of input. */ public class Driver { public static void main(String [] args) { Scanner kbd = new Scanner(System.in); String line = kbd.nextLine(); // Make 4 copies of the input. One for each sorting algorithm. Array a = new Array(line); Array b = new Array(a); Array c = new Array(b); Array d = new Array(c); // Call the sorting algorithms. Take note of the times. long t0 = System.currentTimeMillis(); a.selectionSort(); long t1 = System.currentTimeMillis(); b.insertionSort(); long t2 = System.currentTimeMillis(); c.bubbleSort(); long t3 = System.currentTimeMillis(); d.swapSort(); long t4 = System.currentTimeMillis(); // Because the arrays could be large, we don't need to print them // out. Use Tester.java to look at the output. Here we only want // to know the execution times. System.out.printf("Selection %d ms\n", t1 - t0); System.out.printf("Insertion %d ms\n", t2 - t1); System.out.printf("Bubble %d ms\n", t3 - t2); System.out.printf("Swap %d ms\n", t4 - t3); } }