Homogeneous Container BS_Tree_String class NAME BS_Tree_String - store Strings in a binary search tree FILES BS_Tree_String.java BST_String_Iterator.java Comparison_String.java BS_Tree.java BST_Iterator.java BST_Node.java Comparison.java SYNOPSIS class BS_Tree_String; DESCRIPTION The BS_Tree_String container stores String values in a binary search tree. The user can insert and delete values from the BS_Tree_String using the methods insert() and remove(). The container also offers iterators for access only and methods for finding a value in the container. METHODS Special methods: public BS_Tree_String(); default constructor. Methods: public int size(); returns the size of the BS_Tree_String; public boolean empty(); returns true if size is 0; public void insert(String value); inserts a new value in the BS_Tree_String. Duplicates are allowed. public boolean remove(String value); removes a value from the tree. Returns true if value was found and removed, false if the value wasn't found. public BST_Iterator find(String value); returns an iterator to the first element with the given value found in the BS_Tree_String. Returns an iterator for which atEnd() returns true if such element is not found. public BST_String_Iterator iterator(); returns an iterator to the first value in the BS_Tree_String. The iterator allows the user to move inorder over the values in the tree. Comments: BST_String_Iterator is a class that defines the following methods: public boolean atEnd(); returns true if iterator went past the last element of the container. public void next(); move the iterator to the next element in the container. public String current(); returns the current element pointed by the iterator. EXAMPLES: class BST_String_Test { static public void main(String[] args) { BS_Tree_String bsts = new BS_Tree_String(); bsts.insert("C"); bsts.insert("B"); bsts.insert("D"); bsts.insert("B"); bsts.insert("A"); System.out.print("after initialization: "); BST_String_Iterator iter = bsts.iterator(); while (!iter.atEnd()) { System.out.print( iter.current() + " " ); iter.next(); } System.out.println(); System.out.print("contents >= B: "); iter = bsts.find("B"); while (!iter.atEnd()) { System.out.print( iter.current() + " " ); iter.next(); } System.out.println(); System.out.print("after removal of one B: "); bsts.remove("B"); iter = bsts.iterator(); while (!iter.atEnd()) { System.out.print( iter.current() + " " ); iter.next(); } System.out.println(); } } BUGS No known bugs at this time. Laurentiu Cristofor Last Change: November 6th, 1998