Homogeneous Container BS_Tree_int class NAME BS_Tree_int - store integers in a binary search tree FILES BS_Tree_int.java BST_int_Iterator.java Comparison_Integer.java BS_Tree.java BST_Iterator.java BST_Node.java Comparison.java SYNOPSIS class BS_Tree_int; DESCRIPTION The BS_Tree_int container stores int values in a binary search tree. The user can insert and delete values from the BS_Tree_int 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_int(); default constructor. Methods: public int size(); returns the size of the BS_Tree_int; public boolean empty(); returns true if size is 0; public void insert(int value); inserts a new value in the BS_Tree_int. Duplicates are allowed. public boolean remove(int 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(int value); returns an iterator to the first element with the given value found in the BS_Tree_int. Returns an iterator for which atEnd() returns true if such element is not found. public BST_int_Iterator iterator(); returns an iterator to the first value in the BS_Tree_int. The iterator allows the user to move inorder over the values in the tree. Comments: BST_int_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 int current() throws NullPointerException; returns the current element pointed by the iterator. Throws NullPointerException if iterator is past the end of the BS_Tree_int. EXAMPLES: class BST_int_Test { static public void main(String[] args) { BS_Tree_int bsti = new BS_Tree_int(); bsti.insert(16); bsti.insert(8); bsti.insert(24); bsti.insert(8); bsti.insert(7); System.out.print("after initialization: "); BST_int_Iterator iter = bsti.iterator(); while (!iter.atEnd()) { System.out.print( iter.current() + " " ); iter.next(); } System.out.println(); System.out.print("contents >= 8: "); iter = bsti.find(8); while (!iter.atEnd()) { System.out.print( iter.current() + " " ); iter.next(); } System.out.println(); System.out.print("after removal of one 8: "); bsti.remove(8); iter = bsti.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