public class BTnode<E>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
BTnode.Visitor<E>
This interface forces users of BTnode to provide a visit method to specify
how a node's data is handled when it is "visited".
|
Constructor and Description |
---|
BTnode(E initialData)
Initialize a BTnode with a specified initial data and no children.
|
BTnode(E initialData,
BTnode<E> initialLeft)
Initialize a BTnode with a specified initial data and link to
left child.
|
BTnode(E initialData,
BTnode<E> initialLeft,
BTnode<E> initialRight)
Initialize a BTnode with a specified initial data and links
children.
|
Modifier and Type | Method and Description |
---|---|
E |
getData()
Accessor method to get the data from this node.
|
BTnode<E> |
getLeft()
Accessor method to get a reference to the left child of this node.
|
BTnode<E> |
getRight()
Accessor method to get a reference to the right child of this node.
|
void |
setData(E newData)
Modification method to set the data in this node.
|
void |
setLeft(BTnode<E> newLeft)
Modification method to set the link to the left child of this node.
|
void |
setRight(BTnode<E> newRight)
Modification method to set the link to the right child of this node.
|
public BTnode(E initialData, BTnode<E> initialLeft, BTnode<E> initialRight)
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.
Postcondition:
This node contains the specified data and links to its children.public BTnode(E initialData, BTnode<E> initialLeft)
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.
Postcondition:
This node contains the specified data and links to its children.public BTnode(E initialData)
initialData
- the initial data of this new node
Postcondition:
This node contains the specified data and no children.public E getData()
-
- nonepublic BTnode<E> getLeft()
-
- nonepublic BTnode<E> getRight()
-
- nonepublic void setData(E newData)
newData
- the new data to place in this node
Postcondition:
The data of this node has been set to newData.public void setLeft(BTnode<E> 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)
Postcondition:
The link to the left child of this node has been set to newLeft.
Any other node (that used to be the left child) is no longer connected
to this node.public void setRight(BTnode<E> newRight)
newRight
- 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)
Postcondition:
The link to the right child of this node has been set to newRight.
Any other node (that used to be the right child) is no longer connected
to this node.