001package algs23;
002import stdlib.*;
003import java.util.Arrays;
004/* ***********************************************************************
005 *  Compilation:  javac IntegerSort.java
006 *  Execution:    java IntegerSort N < input.txt
007 *  Dependencies: StdIn.java
008 *
009 *************************************************************************/
010
011public class XIntegerSort {
012
013        public static void main(String[] args) {
014                args = new String[] { "500000" }; StdIn.fromFile ("data/antiquicksort500K.txt");
015                int N = Integer.parseInt(args[0]);
016
017                // initialize and read in data
018                Stopwatch timer1 = new Stopwatch();
019                int[] a = new int[N];
020                for (int i = 0; i < N; i++)
021                        a[i] = StdIn.readInt();
022                double elapsed1 = timer1.elapsedTime();
023                System.err.println("Input:  " + elapsed1 + " seconds");
024
025                // sort
026                Stopwatch timer2 = new Stopwatch();
027                Arrays.sort(a, 0, N);
028                double elapsed2 = timer2.elapsedTime();
029                System.err.println("Sort:   " + elapsed2 + " seconds");
030
031                // print first 10 values in sorted order
032                for (int i = 0; i < N && i < 10; i++)
033                        StdOut.println(a[i]);
034                StdOut.println("...");
035        }
036
037}