assignment4
Class TreeNode
java.lang.Object
assignment4.TreeNode
- All Implemented Interfaces:
- java.lang.Comparable<TreeNode>
public class TreeNode
- extends java.lang.Object
- implements java.lang.Comparable<TreeNode>
Utility binary-tree (Huffman tree) node for Huffman coding.
This is a simple, standard binary-tree node implementing
the comparable interface based on weight.
Constructor Summary |
TreeNode(int value,
int weight)
construct leaf node (null children) |
TreeNode(int value,
int weight,
TreeNode ltree,
TreeNode rtree)
construct internal node (with children) |
Method Summary |
int |
compareTo(TreeNode rhs)
Return value based on comparing this TreeNode to another. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
myValue
public int myValue
myWeight
public int myWeight
myLeft
public TreeNode myLeft
myRight
public TreeNode myRight
TreeNode
public TreeNode(int value,
int weight)
- construct leaf node (null children)
- Parameters:
value
- is the value stored in the node (e.g., character)weight
- is used for comparison (e.g., count of # occurrences)
TreeNode
public TreeNode(int value,
int weight,
TreeNode ltree,
TreeNode rtree)
- construct internal node (with children)
- Parameters:
value
- is stored as value of nodeweight
- is weight of nodeltree
- is left subtreertree
- is right subtree
compareTo
public int compareTo(TreeNode rhs)
- Return value based on comparing this TreeNode to another.
- Specified by:
compareTo
in interface java.lang.Comparable<TreeNode>
- Returns:
- -1 if this < o, +1 if this > o, and 0 if this == 0