Say you have a C++ program that must read in text from a given .txt file. The program will:
- compute number of occurrences of each char in the file, then each unique char (and its frequency) will be stored as a new tree node
- The program then builds a min-heap containing these nodes, then the Huffman Code Tree is built using this min-heap.
- Traversals (pre-order and in-order) will be written to output file. Each internal node of tree will have label I:xxx, where xxx is the int label, and leaves have L:xxx
- The program finally constructs a table that contains the encoding (ASCII based, not true .bin version) of each character stored as a string
I suppose I would store each node within a huffman class like this:
struct CharNode {
char value;
int frequency;
bool internal;
int label;
CharNode *parent;
CharNode *left_child;
CharNode *right_child;
};
I am not exactly sure where to proceed. Any help would be much appreciated!