01: import javax.swing.JOptionPane;
02: 
03: /**
04:    This program measures how long it takes to sort an
05:    array of a user-specified size with the selection
06:    sort algorithm.
07: */
08: public class SelectionSortTimer
09: {  
10:    public static void main(String[] args)
11:    {  
12:       String input = JOptionPane.showInputDialog(
13:          "Enter array size:");
14:       int n = Integer.parseInt(input);
15: 
16:       // construct random array
17:    
18:       int[] a = ArrayUtil.randomIntArray(n, 100);
19:       SelectionSorter sorter = new SelectionSorter(a);
20:       
21:       // use stopwatch to time selection sort
22:       
23:       StopWatch timer = new StopWatch();
24:       
25:       timer.start();
26:       sorter.sort();
27:       timer.stop();
28:       
29:       System.out.println("Elapsed time: " 
30:          + timer.getElapsedTime() + " milliseconds");
31:       System.exit(0);
32:    }
33: }
34: 
35: