static void Main(string[] args) { // ------------------- Variable Declarations string inputText = ""; // text to be encoded and decoded. // ------------------- Input Console.Write("Enter a string to be huffman encoded: "); inputText = Console.ReadLine(); Console.WriteLine("The text you entered is: \"{0}\"", inputText); // ------------------- Processing // Group the characters into a collection of Keys (the characters) and Counts (frequencies) var aggregatedCharacters = inputText.GroupBy(character => character).Select(group => new { character = group.Key, frequency = group.Count() }); // Priority Queue of HuffmanNodes of CharFreqPairs var charFreqPriorityQueue = new PriorityQueue<HuffmanNode<CharFreqPair>>(aggregatedCharacters.Count()); // Add the Character:Frequency pairs to the Priority Queue foreach (var aggregatedCharacter in aggregatedCharacters) charFreqPriorityQueue.Add(new HuffmanNode<CharFreqPair>(new CharFreqPair(aggregatedCharacter.frequency, aggregatedCharacter.character))); // Create HuffmanTree object var huffmanTree = new HuffmanTree(charFreqPriorityQueue); string testing = huffmanTree.EncodeText(inputText); Console.WriteLine("The encoded text is: \"{0}\"", testing); testing = huffmanTree.DecodeText(testing); Console.WriteLine("The decoded text is: \"{0}\"", testing); //huffmanTree.Print(); // Pause before exiting Console.WriteLine("Press return to exit..."); Console.ReadLine(); }