Java Quick-Sort (I)



next up previous WS Presentations Main Page
Next: Java Quick-Sort (II) Up: Document: intro Previous: LP/CLP Quick-Sort

Java Quick-Sort (I)

import java.util.Date;
import java.util.Random;

class QSortAlgorithm {
    static public void main(String args[]) {
        int n = Integer.parseInt(args[0]);
        int a[] = new int[n];
        long time;
        initialize(a, n);
        System.out.println("Sorting "+n+" elements...");
        time = (new Date()).getTime();
        sort(a);
        time = (new Date()).getTime() - time;
        System.out.println("Sorted in "+time+" milliseconds.");
    }
    static void initialize(int a[], int n) {
        Random random;
        random = new Random();
        for (int i=0; i < n; i++) {
            a[i] = random.nextInt();
        }
    }



Thu Jan 18 11:20:31 MET 1996 <herme@fi.upm.es>-<webmaster@clip.dia.fi.upm.es>