UNB/ CS/ David Bremner/ teaching/ java/ Dictionary3.java
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.util.Vector;

public class Dictionary3 {
    public static void main(String [] args)
        throws IOException{
        System.out.println("Reading sorted dictionary");

        Scanner words=
            new Scanner(new File(args[0]));

        Vector<String> list=new Vector<String>();

        int count=0;
        while(words.hasNext()){
            list.addElement(words.next());
            count++;
            if (count % 1000 == 0)
                System.out.println("Read "+ count);
        }

        BinarySearchTree<String> dict = BinarySearchTree.fromSorted(list);

        System.out.println("Tree depth = " + dict.depth());
        System.out.println("First word = " + dict.first());
        System.out.println("Last word = " + dict.last());

        System.out.print("Ready: ");
        Scanner query = new Scanner(System.in);

        while (query.hasNext()){
            String word = query.next().toLowerCase();

            if (dict.search(word))
                System.out.println(word +
                                   " found.");
            else
                System.out.println(word +
                                   " not found. ");
            System.out.print("Ready: ");
        }
    }
}