Example #1
0
        private static void determineChildNodes(List <HuffmanNode> huffmanNodes)
        {
            while (huffmanNodes.Count > 1)
            {
                huffmanNodes.Sort();

                List <HuffmanNode> twoLeastFrequentNodes   = huffmanNodes.Take(2).ToList();
                HuffmanNode        leastFrequentNode       = twoLeastFrequentNodes.First();
                HuffmanNode        secondLeastFrequentNode = twoLeastFrequentNodes.Last();
                huffmanNodes.RemoveRange(0, 2);

                HuffmanNode parentNode = leastFrequentNode.JoinWith(secondLeastFrequentNode);
                huffmanNodes.Add(parentNode);
            }
        }
Example #2
0
 public HuffmanNode(string symbol, int frequency, string code, HuffmanNode left, HuffmanNode right, HuffmanNode parent)
 {
     this.Symbol = symbol;
     this.Frequency = frequency;
     this.Code = code;
     this.Left = left;
     this.Right = right;
     this.Parent = parent;
 }