I am trying to create a Huffman tree the question I read is very strange for me, it is as follows:
Given the following data structure:
struct huffman { unsigned char sym; /* symbol */ struct huffman *left, *right; /* left and right subtrees */ };write a program that takes the name of a binary file as sole argument, builds the Huffman tree of that file assuming that atoms (elementary symbols) are 8-bit unsigned characters, and prints the tree as well as the dictionary.
allocations must be done using nothing else than malloc(), and sorting can be done using qsort().
Here the thing which confuses me is that to write a program to create a huffman tree we just need to do following things:
- We need to take a frequency array (That could be
Farray[]={.......}) - Sort it and add the two smallest nodes to form a tree until it don't left 1 final node(which is head).
Now the question is here: why and where do we need those unsigned char data? (what type of unsigned char data this question want, I think only frequency is enough to display a Huffman tree)?