Homework 4
Goals
- Implement ADT's for list and binary tree
- Use these ADT's in code.
Write a program that will encode a message using Huffman code.
- Prompt for an input file
- Prompt for an output file
- Calculate the alphabet and frequency distribution for the alphabet
represented in the input file. You must use the STL vector
class for this.
- Build a Huffman code for the message in the input file.
- Encode the message in the input file using your code.
- Decode your encoded message.
For this homework you may NOT use STL container classe for LIST.
Implement an ADT for a binary tree and a doubly linked list. You do not
need to make fully templated ADT's, but you must implement these ADT's.
Use the ADTs described in the book, but add any functions that you need.
(such as merge for two trees to create a third)
Use your tree and list ADT to implement Huffman's algorithm.
When building your code, number left child with a 0 and right child with
a 1.
When selecting the minimum character, if frequencies are equal, select the
node with the lowest letter.
When combining two trees, the new root should be assigned the lowest "letter"
of the two sub trees.
Your program should produce three files
- A file containing the constructed Huffman code, each line should have a letter, an encoding for that letter, and the frequency of that letter (to 4 decimal places) (outputfile.code)
- A file containing the encoded message, in ascii. (outputfile.enc)
- A file containing the decoded message. (outputfile.dec)
When you have finished this project, please e-mail all of the files to me as
a single tar file.