|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstructure.BinaryTree
public class 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 |
Constructor Summary | |
---|---|
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. |
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 |
void |
setLeft(BinaryTree newLeft)
Update the left subtree 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 |
Object |
value()
Returns value associated with this node |
Methods inherited from class java.lang.Object |
---|
equals, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final BinaryTree EMPTY
Constructor Detail |
---|
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 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()
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 toString()
toString
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |