| 
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectstructure.AbstractStructure<ELTTYPE>
structure.RedBlackSearchTree<ELTTYPE>
public class RedBlackSearchTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Red black trees, are binary trees that guarantee the following three properties. 
 1. Every child of every leaf is considered black
 
 2. Every red node has two black children
 3. Every path from a node to a descendant leaf contains the same
    number of black nodes. 
 
These properties ensure that elements can be inserted, deleted, and located in logorithmic time.
Example usage:
To create a red-black tree containing the months of the year and to print out this tree as it grows we could use the following
 public static void main(String[] argv){
     RedBlackSearchTree test = new RedBlackSearchTree();
       
     //declare an array of months
     String[] months = new String[]{"March", "May", "November", "August", 
                              "April", "January", "December", "July",
                                      "February", "June", "October", "September"};
      
     //add the months to the tree and print out the tree as it grows
     for(int i=0; i < months.length; i++){
        test.add(months[i]);
        System.out.println("Adding: " + months[i] + "\n" +test.treeString());
      }
  }
 
AVLTree, 
SplayTree, 
BinaryTree| Constructor Summary | |
|---|---|
RedBlackSearchTree()
Constructs a red-black search tree with no data  | 
|
| Method Summary | |
|---|---|
 void | 
add(ELTTYPE value)
Add a (possibly duplicate) value to the red-black tree, and ensure that the resulting tree is a red-black tree.  | 
 void | 
clear()
Removes all data from the binary search tree  | 
 boolean | 
contains(ELTTYPE value)
Determines if the red-black search tree contains a value  | 
 int | 
hashCode()
Returns the hashCode of the value stored by this object.  | 
 boolean | 
isEmpty()
Checks for an empty binary search tree  | 
 boolean | 
isRedBlack()
Returns true iff this tree is a red-black tree.  | 
 java.util.Iterator<ELTTYPE> | 
iterator()
Returns an iterator over the red-black search tree.  | 
 ELTTYPE | 
remove(ELTTYPE value)
Remove an value "equals to" the indicated value.  | 
 int | 
size()
Determines the number of data values within the tree  | 
 java.lang.String | 
toString()
Returns a string representing tree  | 
 java.lang.String | 
treeString()
Returns a (possibly long) string representing tree.  | 
| Methods inherited from class structure.AbstractStructure | 
|---|
elements, values | 
| Methods inherited from class java.lang.Object | 
|---|
equals, getClass, notify, notifyAll, wait, wait, wait | 
| Methods inherited from interface structure.Structure | 
|---|
elements, values | 
| Constructor Detail | 
|---|
public RedBlackSearchTree()
| Method Detail | 
|---|
public boolean isEmpty()
isEmpty in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>isEmpty in class AbstractStructure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>public void clear()
clear in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>public int size()
size in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>public void add(ELTTYPE value)
add in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>val - A reference to non-null objectpublic ELTTYPE remove(ELTTYPE value)
remove in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>val - Value sought to be removed from tree
public boolean contains(ELTTYPE value)
contains in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>contains in class AbstractStructure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>val - The value sought.  Should be non-null
public boolean isRedBlack()
public java.util.Iterator<ELTTYPE> iterator()
iterator in interface java.lang.Iterable<ELTTYPE extends java.lang.Comparable<ELTTYPE>>iterator in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>AbstractIterator, 
Iterator, 
Enumeration, 
Structure.elements()public java.lang.String treeString()
toString() in that toString() outputs 
 a single line representation of the contents of the tree.
 treeString, however, prints out a graphical 
 representations of the tree's structure.
public java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class AbstractStructure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
  | 
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||