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:

  • Compute the Huffman code tree from the two traversals.
  • Decode the text, writing the output to standard output (cout).

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:

  • You hould build all the data structures that you use yourself.
  • Your makefile should build the executable named "decode".
  • You must use good object based organization, i.e. use classes in an appropriate way.

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!
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.