Encode() public method

public Encode ( string source ) : BitArray
source string
return BitArray
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the string:");
            string      input       = Console.ReadLine();
            HuffmanTree huffmanTree = new HuffmanTree();

            // Build the Huffman tree
            huffmanTree.Build(input);

            // Encode
            BitArray encoded = huffmanTree.Encode(input);

            Console.Write("Encoded: ");
            foreach (bool bit in encoded)
            {
                Console.Write((bit ? 1 : 0) + "");
            }
            Console.WriteLine();

            // Decode
            string decoded = huffmanTree.Decode(encoded);

            Console.WriteLine("Decoded: " + decoded);

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Input a test string:");
            string inputString = Console.ReadLine();

            var huffmanTree = new HuffmanTree();

            huffmanTree.Build(inputString);

            string encodedString = huffmanTree.Encode(inputString);

            Console.WriteLine(encodedString);

            string decodedString = huffmanTree.Decode(encodedString);

            Console.WriteLine(decodedString);
        }