diff options
Diffstat (limited to 'lib/Huffman.cc')
-rw-r--r-- | lib/Huffman.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Huffman.cc b/lib/Huffman.cc new file mode 100644 index 0000000..aadf927 --- /dev/null +++ b/lib/Huffman.cc @@ -0,0 +1,31 @@ +#include <stdio.h> +#include <iostream.h> +#include "config.h" +#include "Huffman.h" + +HTree *Coder(PriorityList * P) +{ + int n = P->n(), i, f1, f2; + HTree *x, *y, *z; + Datas_t tx, ty; + + x = y = z = NULL; + + for (i = 0; i < n - 1; i++) { + f1 = P->Extract_Min(tx); + f2 = P->Extract_Min(ty); + x = (HTree *) tx; + y = (HTree *) ty; + z = new HTree(x, y); + P->Insert(z->ReadFreq(), z); + } + + P->Extract_Min(((Datas_t) z)); + return z; +} + +void HInsert(PriorityList * P, int freq, char *object) +{ + HTree * leaf = new HTree(freq, object); + P->Insert(freq, (Datas_t) leaf); +} |