assignment4
Class TreeNode

java.lang.Object
  extended by 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.


Field Summary
 TreeNode myLeft
           
 TreeNode myRight
           
 int myValue
           
 int myWeight
           
 
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
 

Field Detail

myValue

public int myValue

myWeight

public int myWeight

myLeft

public TreeNode myLeft

myRight

public TreeNode myRight
Constructor Detail

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 node
weight - is weight of node
ltree - is left subtree
rtree - is right subtree
Method Detail

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