/// <summary> /// /// </summary> /// <param name="nodes"></param> /// <returns></returns> private static HuffmanNode ConstructHuffmanTree(ICollection <HuffmanNode> nodes) { if (nodes.Count < 2) { return(nodes.First()); //finished } var left = nodes.Pop(); var right = nodes.Pop(); var node = new HuffmanNode(left, right); return(ConstructHuffmanTree(nodes.AddSorted(node))); }