Example #1
0
 public static void getHuffmanCode()
 {
     if (root.isLeafNode())
     {
         huffmanCode.Add("1", root.symbol);
     }
     else
     {
         buildHuffmanCode(root, "");
     }
 }
 /// <summary>
 /// Build huffman code
 /// </summary>
 /// <param name="node">Root node of huffman's tree</param>
 /// <param name="route">Initial route</param>
 private static void buildHuffmanCode(HuffmanNode node, string route)
 {
     if (node.isLeafNode())
     {
         huffmanCode.Add(node.symbol, route);
     }
     else
     {
         if (node.leftChild != null)
         {
             buildHuffmanCode(node.leftChild, route + "0");
         }
         if (node.rightChild != null)
         {
             buildHuffmanCode(node.rightChild, route + "1");
         }
     }
 }