com.mhhe.clrs2e
Class BinarySearchTree.Node

java.lang.Object
  |
  +--com.mhhe.clrs2e.BinarySearchTree.Node
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
RedBlackTree.Node
Enclosing class:
BinarySearchTree

protected class BinarySearchTree.Node
extends java.lang.Object
implements java.lang.Comparable

Inner class for a node of a binary search tree. May be extended in subclasses of BinarySearchTree.


Field Summary
protected  java.lang.Comparable data
          The data stored in the node.
protected  BinarySearchTree.Node left
          The node's left child.
protected  BinarySearchTree.Node parent
          The node's parent.
protected  BinarySearchTree.Node right
          The node's right child.
 
Constructor Summary
BinarySearchTree.Node(java.lang.Comparable data)
          Initializes a node with the data and makes other pointers nil.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this node to another node.
 java.lang.String toString()
          Returns the data instance variable of this node as a String.
 java.lang.String toString(int depth)
          Returns a multiline String representation of the subtree rooted at this node, representing the depth of each node by two spaces per depth preceding the String representation of the node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected java.lang.Comparable data
The data stored in the node.


parent

protected BinarySearchTree.Node parent
The node's parent.


left

protected BinarySearchTree.Node left
The node's left child.


right

protected BinarySearchTree.Node right
The node's right child.

Constructor Detail

BinarySearchTree.Node

public BinarySearchTree.Node(java.lang.Comparable data)
Initializes a node with the data and makes other pointers nil.

Parameters:
data - Data to save in the node.
Method Detail

compareTo

public int compareTo(java.lang.Object o)
Compares this node to another node. The comparison is based on the data instance variables of the two nodes.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The other node.
Returns:
A negative integer if this node is less than o; 0 if this node equals o; a positive integer if this node is greater than o.
Throws:
java.lang.ClassCastException - if o is not a Node.

toString

public java.lang.String toString()
Returns the data instance variable of this node as a String.

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int depth)
Returns a multiline String representation of the subtree rooted at this node, representing the depth of each node by two spaces per depth preceding the String representation of the node.

Parameters:
depth - Depth of this node.