|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.BinaryTree
This class implements a single node of a binary tree. It is a recursive structure. Relationships between nodes are doubly linked, with parent and child references. Many characteristics of trees may be detected with static methods.
BinaryTree
,
BinarySearchTree
Field Summary | |
static BinaryTree |
EMPTY
The unique empty node |
protected BinaryTree |
left
The left child of this node, or EMPTY |
protected BinaryTree |
parent
The parent of this node |
protected BinaryTree |
right
The left child of this node, or EMPTY |
protected Object |
val
The value associated with this node |
Constructor Summary | |
private |
BinaryTree()
A one-time constructor, for constructing empty trees. |
|
BinaryTree(Object value)
Constructs a tree node with no children. |
|
BinaryTree(Object value,
BinaryTree left,
BinaryTree right)
Constructs a tree node with no children. |
Method Summary | |
int |
depth()
Compute the depth of a node. |
private String |
getHand()
Support method for toString() . |
int |
hashCode()
|
int |
height()
Returns height of node in tree. |
AbstractIterator |
inorderIterator()
Return an iterator to traverse the elements of subtree in-order |
boolean |
isBalanced()
Return true iff the tree is height balanced. |
boolean |
isComplete()
Return whether tree is complete. |
boolean |
isEmpty()
Returns true if tree is empty. |
boolean |
isFull()
Returns true if tree is full. |
boolean |
isLeftChild()
Determine if this node is a left child |
boolean |
isRightChild()
Determine if this node is a right child |
Iterator |
iterator()
Generate an in-order iterator of subtree |
BinaryTree |
left()
Get left subtree of current node |
AbstractIterator |
levelorderIterator()
Method to return a level-order iterator of subtree |
BinaryTree |
parent()
Get reference to parent of this node |
AbstractIterator |
postorderIterator()
Return an iterator to traverse the elements of subtree in post-order |
AbstractIterator |
preorderIterator()
Return an iterator to traverse nodes of subtree in-order |
BinaryTree |
right()
Get right subtree of current node |
BinaryTree |
root()
Returns reference to root of tree containing n |
protected void |
rotateLeft()
Method to perform a left rotation of tree about this node Node must have a right child. |
protected void |
rotateRight()
Method to perform a right rotation of tree about this node Node must have a left child. |
void |
setLeft(BinaryTree newLeft)
Update the left subtree of this node. |
protected void |
setParent(BinaryTree newParent)
Update the parent of this node |
void |
setRight(BinaryTree newRight)
Update the right subtree of this node. |
void |
setValue(Object value)
Set's value associated with this node |
int |
size()
Returns the number of descendants of node |
String |
toString()
Returns a representation the subtree rooted at this node |
String |
treeString()
Returns a string representing the tree rooted at this node. |
Object |
value()
Returns value associated with this node |
Methods inherited from class java.lang.Object |
|
Field Detail |
protected Object val
protected BinaryTree parent
protected BinaryTree left
protected BinaryTree right
public static final BinaryTree EMPTY
Constructor Detail |
private BinaryTree()
public BinaryTree(Object value)
value
- A (possibly null) value to be referenced by nodepublic BinaryTree(Object value, BinaryTree left, BinaryTree right)
value
- A (possibly null) value to be referenced by nodeleft
- The subtree to be left subtree of noderight
- The subtree to be right subtree of nodeMethod Detail |
public BinaryTree left()
public BinaryTree right()
public BinaryTree parent()
public void setLeft(BinaryTree newLeft)
newLeft
- The root of the new left subtreepublic void setRight(BinaryTree newRight)
newRight
- A reference to the new right subtree of this nodeprotected void setParent(BinaryTree newParent)
newParent
- A reference to the new parent of this nodepublic int size()
public BinaryTree root()
public int height()
public int depth()
public boolean isFull()
public boolean isEmpty()
public boolean isComplete()
public boolean isBalanced()
public Iterator iterator()
public AbstractIterator preorderIterator()
public AbstractIterator inorderIterator()
public AbstractIterator postorderIterator()
public AbstractIterator levelorderIterator()
protected void rotateRight()
protected void rotateLeft()
public boolean isLeftChild()
public boolean isRightChild()
public Object value()
public void setValue(Object value)
value
- The new value of this nodepublic int hashCode()
hashCode
in class Object
public String treeString()
private String getHand()
toString()
. Returns R if this is node
is a right child, L if this node is a left child and Root if this
node is the root.public String toString()
toString
in class Object
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |