From dfd868ecf9e37a5e6954a073c3ba43a970f7ca54 Mon Sep 17 00:00:00 2001 From: Pixel <> Date: Mon, 5 Mar 2001 01:30:36 +0000 Subject: Projet quasi fini... --- lib/Huffman.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/Huffman.cc (limited to 'lib/Huffman.cc') 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 +#include +#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); +} -- cgit v1.2.3