|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure5.BinaryTree<E>
public class BinaryTree<E>
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.
structure.BinaryTree
,
structure.BinarySearchTree
Constructor Summary | |
---|---|
BinaryTree()
A one-time constructor, for constructing empty trees. |
|
BinaryTree(E value)
Constructs a tree node with no children. |
|
BinaryTree(E value,
BinaryTree<E> left,
BinaryTree<E> right)
Constructs a tree node with two children. |
Method Summary | |
---|---|
int |
depth()
Compute the depth of a node. |
int |
hashCode()
|
int |
height()
Returns height of node in tree. |
AbstractIterator<E> |
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<E> |
iterator()
Generate an in-order iterator of subtree |
BinaryTree<E> |
left()
Get left subtree of current node |
AbstractIterator<E> |
levelorderIterator()
Method to return a level-order iterator of subtree |
BinaryTree<E> |
parent()
Get reference to parent of this node |
AbstractIterator<E> |
postorderIterator()
Return an iterator to traverse the elements of subtree in post-order |
AbstractIterator<E> |
preorderIterator()
Return an iterator to traverse nodes of subtree in-order |
BinaryTree<E> |
right()
Get right subtree of current node |
BinaryTree<E> |
root()
Returns reference to root of tree containing n |
void |
setLeft(BinaryTree<E> newLeft)
Update the left subtree of this node. |
void |
setRight(BinaryTree<E> newRight)
Update the right subtree of this node. |
void |
setValue(E 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. |
E |
value()
Returns value associated with this node |
Methods inherited from class java.lang.Object |
---|
equals, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BinaryTree()
public BinaryTree(E value)
value
- A (possibly null) value to be referenced by nodepublic BinaryTree(E value, BinaryTree<E> left, BinaryTree<E> 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<E> left()
public BinaryTree<E> right()
public BinaryTree<E> parent()
public void setLeft(BinaryTree<E> newLeft)
newLeft
- The root of the new left subtreepublic void setRight(BinaryTree<E> newRight)
newRight
- A reference to the new right subtree of this nodepublic int size()
public BinaryTree<E> root()
public int height()
public int depth()
public boolean isFull()
public boolean isEmpty()
public boolean isComplete()
public boolean isBalanced()
public Iterator<E> iterator()
public AbstractIterator<E> preorderIterator()
public AbstractIterator<E> inorderIterator()
public AbstractIterator<E> postorderIterator()
public AbstractIterator<E> levelorderIterator()
public boolean isLeftChild()
public boolean isRightChild()
public E value()
public void setValue(E value)
value
- The new value of this nodepublic int hashCode()
hashCode
in class Object
public String treeString()
public String toString()
toString
in class Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |