SystemSort.java


Below is the syntax highlighted version of SystemSort.java from §4.2 Sorting and Searching.


/******************************************************************************
 *  Compilation:  javac SystemSort.java
 *  Execution:    java SystemSort n < mobydick.txt
 *
 ******************************************************************************/

import java.util.Arrays;

public class SystemSort {

    public static double timeit(int n) {
        double[] a = new double[n];
        for (int i = 0; i < n; i++)
            a[i] = StdRandom.uniformDouble(0.0, 1.0);
        Stopwatch timer = new Stopwatch();
        Arrays.sort(a);
        return timer.elapsedTime();
    }

    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        for (int i = 0; i < 100; i++)
            StdOut.println(timeit(n));
    }
}


Copyright © 2000–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:29:15 EDT 2022.