AATree - package DataStructures; / / / / / / / / / / / / /...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
package DataStructures; // AATree class // // CONSTRUCTION: with no initializer // // ******************PUBLIC OPERATIONS********************* // void insert( x ) --> Insert x // void remove( x ) --> Remove x // Comparable find( x ) --> Return item that matches x // Comparable findMin( ) --> Return smallest item // Comparable findMax( ) --> Return largest item // boolean isEmpty( ) --> Return true if empty; else false // void makeEmpty( ) --> Remove all items // void printTree( ) --> Print tree in sorted order /** * Implements an AA-tree. * Note that all "matching" is based on the compareTo method. * @author Mark Allen Weiss */ public class AATree { /** * Construct the tree. */ public AATree( ) { root = nullNode; } /** * Insert into the tree. Does nothing if x is already present. * @param x the item to insert. */ public void insert( Comparable x ) { root = insert( x, root ); } /** * Remove from the tree. Does nothing if x is not found. * @param x the item to remove. */ public void remove( Comparable x ) { deletedNode = nullNode; root = remove( x, root ); } /** * Find the smallest item in the tree. * @return the smallest item or null if empty. */ public Comparable findMin( ) { if( isEmpty( ) ) return null;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
AANode ptr = root; while( ptr.left != nullNode ) ptr = ptr.left; return ptr.element; } /** * Find the largest item in the tree. * @return the largest item or null if empty.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

AATree - package DataStructures; / / / / / / / / / / / / /...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online