import TreeVertex; /** * Generic trees. * * @author Samuel A. Rebelsky * @author CS152 2000S * @version 1.0 of April 2000 */ public interface Tree { // +------------+------------------------------------ // | Extractors | // +------------+ /** * Get the vertex at the root of the tree. * Pre: The tree is nonempty. * Post: Returns the vertex at the root. */ public TreeVertex getRoot(); /** * Determine if the tree is empty. * Pre: None * Post: Returns true if the tree is empty and false * otherwise. */ public boolean isEmpty(); // +-----------+------------------------------------- // | Modifiers | // +-----------+ /** * Add a vertex to the tree as a child of a particular vertex. * Builds a vertex for the child. * Pre: The vertex is in the tree. * Post: Added. * @exception Exception * If the vertex limits its number of children. */ public void addChild(TreeVertex parent, Object child) throws Exception; /** * Add a root to an empty tree. * Pre: The tree is empty. * Post: The tree contains one vertex which contains the * specified value. */ public void makeRoot(Object rootValue); /** * Delete a vertex from the tree. An unpleasant operation, * at best. Also deletes everything below the vertex. * Pre: The vertex is in the tree. * Post: Gone. The parent may also have renumbered its * children. */ public void delete(TreeVertex target); } // interface Tree