You are to write a program that reads three text files given as command line parameters. The first file is an inorder traversal of a Huffman code tree and the second parameter is the postorder traversal of the same tree. The third file is the encoded text, given as ASCII 0s and 1s.
Your program should:
The format of the inorder and postorder traversals will be integer values separated by whitespace. The leaves of the tree will be values < 128, representing the ASCII value of the letter. The internal nodes of the tree will be values 128 and greater.
Requirements:
An example run ./decode inorder.txt postorder.txt encoded.txt
inorder.txt:
66 129 76 128 77 130 65
postorder.txt:
66 76 77 128 129 65 130
encoded.txt:
101010010111
Output should be:
ALABAMA
Another example run ./decode inorder.txt postorder.txt encoded.txt
Inorder.txt:
10 128 33 134 121 133 7 138 4 5 106 131 71 143 0 140 32 145 101 141 89 130 108 137 99 144 111 142 116 139 120 129 98 136 104 132 46
postorder.txt:
10 33 128 121 117 133 134 114 106 71 131 5 8 100 32 140 143 101 89 108 130 99 137 141 111 116 120 98 129 104 46 132 136 139 142 144 145
encoded.txt:
100001001011100001111101110100011111001 11100111001110110010001010010111110101010001011111100000001111 101100100110011011011110100001
Output should be:
You decoded the text correctly.
Good job!