Class TwoThreeTreeNode
java.lang.Object
|
+----TwoThreeTreeNode
- public class TwoThreeTreeNode
- extends Object
Source File:
TwoThreeTreeNode.java
Class for for a node of a TwoThreeTree. This is the non-threaded
version. It uses a data member called parent for keeping track
of the node's parent, for use during insertions and deletions.
This version also differs from the example shown in the textbook
in that it does not use the idea of setting unused data members to
MAXKEY, where MAXKEY>key for all key. Instead, we use a data
member called n which holds the number of data elements stored
in the node (either 1 or 2).
- Version:
- 1.0
- Author:
- John Webb
-
lChild
- This node's left child (if node is not a leaf node), or left
thread (if node is a leaf node)
-
lData
- This node's left data element
-
mChild
- This node's middle child
-
parent
- This node's parent.
-
rChild
- This node's right child (if node is not a leaf node), or right
thread (if node is a leaf node)
-
rData
- This node's right data element
-
TwoThreeTreeNode()
-
-
addData(NodeData, TwoThreeTreeNode)
-
Add a NodeData object to a two-node.
-
isLeaf()
-
Determine whether this is a leaf node.
-
isThreeNode()
-
Determine whether this is a three-node.
-
isTwoNode()
-
Determine whether this is a two-node.
-
numElements()
-
Get number of data elements in this node.
-
TwoThreeTreeNode(NodeData)
-
Create a new TwoThreeTreeNode, and add a NodeData object to the node.
lData
public NodeData lData
- This node's left data element
rData
public NodeData rData
- This node's right data element
lChild
public TwoThreeTreeNode lChild
- This node's left child (if node is not a leaf node), or left
thread (if node is a leaf node)
mChild
public TwoThreeTreeNode mChild
- This node's middle child
rChild
public TwoThreeTreeNode rChild
- This node's right child (if node is not a leaf node), or right
thread (if node is a leaf node)
parent
public TwoThreeTreeNode parent
- This node's parent. Though not strictly necessary (we could follow
the threads and/or child links to find the parent) it was included
for efficiency and ease of coding.
TwoThreeTreeNode
public TwoThreeTreeNode()
TwoThreeTreeNode
public void TwoThreeTreeNode(NodeData nd)
- Create a new TwoThreeTreeNode, and add a NodeData object to the node.
Inputs:
nd (NodeData): the NodeData object to add to the new node.
Outputs:
none
Preconditions:
true
Postconditions:
a new TwoThreeTreeNode x exists such that x is a 2-node and
x contains nd as it's only data element
isTwoNode
public boolean isTwoNode()
- Determine whether this is a two-node.
Inputs:
none
Outputs:
isTwoNode (boolean): true if this node is a 2-node, false otherwise
Preconditions:
no two-nodes have non-null right data references
Postconditions:
true has been returned if this is a 2-node, false otherwise
numElements
public int numElements()
- Get number of data elements in this node.
Inputs:
none
Outputs:
numElements (int): 2 if this is a 3-node, otherwise 1
Preconditions:
this node is either a 2-node or a 3-node
Postconditions:
numElements has been returned
isThreeNode
public boolean isThreeNode()
- Determine whether this is a three-node.
Inputs:
none
Outputs:
isThreeNode (boolean): true if this node is a 3-node, false otherwise
Preconditions:
true
Postconditions:
true has been returned if this is a 3-node, false otherwise
isLeaf
public boolean isLeaf()
- Determine whether this is a leaf node.
Inputs:
none
Outputs:
isLeaf (boolean): true if this node is a leaf node, false otherwise
Preconditions:
no leaf nodes have non-null middle children
Postconditions:
isLeaf is true if this is a leaf node, false otherwise
addData
public void addData(NodeData data,
TwoThreeTreeNode subtree)
- Add a NodeData object to a two-node.
Inputs:
data (NodeData): the NodeData object to add to the node
subtree (TwoThreeTreeNode): the subtree that will be added to the
right right of the new data element.
Outputs:
none
Preconditions:
this node is a 2-node
Postconditions:
this node is a three-node containing data