import java.io.*;

public class TrieTest {
    public static void main(String[] args) {
	Trie tree = new Trie();
	boolean b;
	String s;

        System.out.println("Insert words. End with Ctrl-D.");
	while ((s = GetLine()) != null) {
	    System.out.println("Inserting word: " + s);
	    tree.insert(s);
	}

	System.out.println("Choose word to search for. End with Ctrl-D.");
	while ((s = GetLine()) != null) {
	    if (tree.existsVerbose(s)) {
		System.out.println("yes");
	    } else {
		System.out.println("no");
	    }
	}

	System.out.println("Thanks for using a reTRIEval tree to store data.");
    }

    // These are blatantly stolen from Henrik Erikssons Mio.java used in 
    // Datalogi for E. These are not as machine independant as you could 
    // wish for.
    public static boolean EOF() {
	int n = 0;
	System.in.mark(1);
	try {
	    n = System.in.read();
	    System.in.reset();
	} catch (IOException e) {
	    System.err.println("Fel i EOF");
	}

	return (n == -1);	
    }

    public static String GetLine() {
	StringBuffer word = new StringBuffer();
	char c;

	if (EOF()) {
	    return null;
	}
	
	while((c = GetChar()) != '\n') {
	    word.append(c);
	}

	return word.toString();
    }

    public static char GetChar() {
	char c = '\000';

	try {
	    c = (char) System.in.read();
	} catch (IOException e) {
	    System.err.println("Fel i GetChar");
	}
	return c;
    }
}


