// Printing all Tree! Recursive method. public void PrintTree(int level, HuffmanNode node) { if (node == null) { return; } for (int i = 0; i < level; i++) { Console.Write("\t"); } Console.Write("[" + node.symbol + "]"); Console.WriteLine("(" + node.code + ")"); PrintTree(level + 1, node.rightTree); PrintTree(level + 1, node.leftTree); }
// Printing the symbols and codes of the Nodes on the tree. public void PrintfLeafAndCodes(HuffmanNode nodeList) { if (nodeList == null) { return; } if (nodeList.leftTree == null && nodeList.rightTree == null) { Console.WriteLine("Symbol : {0} - Code : {1}", nodeList.symbol, nodeList.code); bw.Write(nodeList.symbol); bw.Write(nodeList.code); codeString += nodeList.code; //Binary(nodeList.code); return; } PrintfLeafAndCodes(nodeList.leftTree); PrintfLeafAndCodes(nodeList.rightTree); }
public int CompareTo(HuffmanNode otherNode) // We just override the CompareTo method. Because when we compare two Node, it must be according to frequencies of the Nodes. { return(this.frequency.CompareTo(otherNode.frequency)); }