|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.colorado.nodes.ShortBTNode
public class ShortBTNode
A ShortBTNode provides a node for a binary tree. Each node
contains a piece of data (which is a reference to an object) and references
to a left and right child. The references to children may be null to indicate
that there is no child. The reference stored in a node can also be null.
Int.MAX_VALUE elements, treeSize, is
wrong.
BTNode,
BooleanBTNode,
ByteBTNode,
CharBTNode,
DoubleBTNode,
FloatBTNode,
IntBTNode,
LongBTNode| Constructor Summary | |
|---|---|
ShortBTNode(short initialData,
ShortBTNode initialLeft,
ShortBTNode initialRight)
Initialize a ShortBTNode with a specified initial data and links
children. |
|
| Method Summary | |
|---|---|
short |
getData()
Accessor method to get the data from this node. |
ShortBTNode |
getLeft()
Accessor method to get a reference to the left child of this node. |
short |
getLeftmostData()
Accessor method to get the data from the leftmost node of the tree below this node. |
ShortBTNode |
getRight()
Accessor method to get a reference to the right child of this node. |
short |
getRightmostData()
Accessor method to get the data from the rightmost node of the tree below this node. |
void |
inorderPrint()
Uses an inorder traversal to print the data from each node at or below this node of the binary tree. |
boolean |
isLeaf()
Accessor method to determine whether a node is a leaf. |
void |
postorderPrint()
Uses a postorder traversal to print the data from each node at or below this node of the binary tree. |
void |
preorderPrint()
Uses a preorder traversal to print the data from each node at or below this node of the binary tree. |
void |
print(int depth)
Uses an inorder traversal to print the data from each node at or below this node of the binary tree, with indentations to indicate the depth of each node. |
ShortBTNode |
removeLeftmost()
Remove the leftmost most node of the tree below this node. |
ShortBTNode |
removeRightmost()
Remove the rightmost most node of the tree below this node. |
void |
setData(short newData)
Modification method to set the data in this node. |
void |
setLeft(ShortBTNode newLeft)
Modification method to set the link to the left child of this node. |
void |
setRight(ShortBTNode newRight)
Modification method to set the link to the right child of this node. |
static ShortBTNode |
treeCopy(ShortBTNode source)
Copy a binary tree. |
static int |
treeSize(ShortBTNode root)
Count the number of nodes in a binary tree. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ShortBTNode(short initialData,
ShortBTNode initialLeft,
ShortBTNode initialRight)
ShortBTNode with a specified initial data and links
children. Note that a child link may be the null reference,
which indicates that the new node does not have that child.
initialData - the initial data of this new nodeinitialLeft - a reference to the left child of this new node--this reference may be null
to indicate that there is no node after this new node.initialRight - a reference to the right child of this new node--this reference may be null
to indicate that there is no node after this new node.
| Method Detail |
|---|
public short getData()
- - none
public ShortBTNode getLeft()
- - none
public short getLeftmostData()
- - none
public short getRightmostData()
- - none
public ShortBTNode getRight()
- - none
public void inorderPrint()
- - none
System.out.println( ) using an inorder traversal.public boolean isLeaf()
- - none
true (if this node is a leaf) or
false (if this node is not a leaf.public void preorderPrint()
- - none
System.out.println( ) using a preorder traversal.public void postorderPrint()
- - none
System.out.println( ) using a postorder traversal.public void print(int depth)
depth - the depth of this node (with 0 for root, 1 for the root's
children, and so on)(
depth is the depth of this node.
System.out.println( ) using an inorder traversal.
The indentation of each line of data is four times its depth in the
tree. A dash "--" is printed at any place where a child has no
sibling.public ShortBTNode removeLeftmost()
- - none
public ShortBTNode removeRightmost()
- - none
public void setData(short newData)
newData - the new data to place in this node
newData.public void setLeft(ShortBTNode newLeft)
newLeft - a reference to the node that should appear as the left child of this node
(or the null reference if there is no left child for this node)
newLeft.
Any other node (that used to be the left child) is no shorter connected to
this node.public void setRight(ShortBTNode newRight)
newLeft - a reference to the node that should appear as the right child of this node
(or the null reference if there is no right child for this node)
newRight.
Any other node (that used to be the right child) is no shorter connected to
this node.public static ShortBTNode treeCopy(ShortBTNode source)
source - a reference to the root of a binary tree that will be copied (which may be
an empty tree where source is null)
source. The return value is a reference to the root of the copy.
java.lang.OutOfMemoryError - Indicates that there is insufficient memory for the new tree.public static int treeSize(ShortBTNode root)
root - a reference to the root of a binary tree (which may be
an empty tree where source is null)
INT.MAX_VALUE.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||