asd_library.tree.avltree
Class AvlTree

java.lang.Object
  |
  +--asd_library.tree.avltree.AvlTree

public class AvlTree
extends java.lang.Object

Implements an AVL tree.


Constructor Summary
AvlTree()
          Construct the tree.
 
Method Summary
 java.lang.Comparable find(java.lang.Comparable x)
          Find an item in the tree.
 java.lang.Comparable findMax()
          Find the largest item in the tree.
 java.lang.Comparable findMin()
          Find the smallest item in the tree.
 void insert(java.lang.Comparable x)
          Insert into the tree; duplicates are ignored.
 boolean isEmpty()
          Test if the tree is logically empty.
 void makeEmpty()
          Make the tree logically empty.
 void printTree()
          Print the tree contents in sorted order.
 void remove(java.lang.Comparable x)
          Remove from the tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AvlTree

public AvlTree()
Construct the tree.

Method Detail

insert

public void insert(java.lang.Comparable x)
Insert into the tree; duplicates are ignored.

Parameters:
x - the item to insert.

remove

public void remove(java.lang.Comparable x)
Remove from the tree. Nothing is done if x is not found.

Parameters:
x - the item to remove.

findMin

public java.lang.Comparable findMin()
Find the smallest item in the tree.

Returns:
smallest item or null if empty.

findMax

public java.lang.Comparable findMax()
Find the largest item in the tree.

Returns:
the largest item of null if empty.

find

public java.lang.Comparable find(java.lang.Comparable x)
Find an item in the tree.

Parameters:
x - the item to search for.
Returns:
the matching item or null if not found.

makeEmpty

public void makeEmpty()
Make the tree logically empty.


isEmpty

public boolean isEmpty()
Test if the tree is logically empty.

Returns:
true if empty, false otherwise.

printTree

public void printTree()
Print the tree contents in sorted order.