UNB/ CS/ David Bremner/ teaching/ old/ cs1083/ java/ Dictionary2.java
import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class Dictionary2 {
    public static void main(String [] args)
        throws IOException{
        System.out.println("Loading dictionary");
        BinarySearchTree<String> dict
            =new BinarySearchTree<String>();

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

        int count=0;
        while(words.hasNext()){
            dict.insert(words.next().toLowerCase());
            count++;
            if (count % 1000 == 0)
                System.out.println("Read "+ count);
        }
        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: ");
        }
    }
}