//  File:  TreeOfDoubles.java

//  Show how to use the Java 2 TreeSet collection

import java.util.TreeSet;
import java.util.Iterator;

public class TreeOfDoubles {

    final static int NUM = 20;

    public static void main(String[] args) {
        System.out.println("A Tree of Doubles");
        System.out.println();

        // Insert NUM random doubles into t...
        System.out.print("Inserting: ");
        TreeSet t = new TreeSet();
        for (int i = 0; i < NUM; i++) {
            double d = ((int)(100.0 * Math.random())) / 10.0;
            System.out.print(" " + d);
            t.add(new Double(d));
        }
        System.out.println();
        System.out.println();

        // Tell about t...
        System.out.println("t contains " + t.size() + " values");
        System.out.println("first=" + t.first() + "   last=" + t.last());
        System.out.println();

        // Show what's in t...
        System.out.print("t contains: ");
        Iterator iter = t.iterator();
        while (iter.hasNext()) {
            System.out.print(" " + iter.next());
        }
        System.out.println();
        System.out.println();
    }
}

