summaryrefslogtreecommitdiff
path: root/lib/Huffman.cc
diff options
context:
space:
mode:
authorPixel <>2001-03-05 01:30:36 +0000
committerPixel <>2001-03-05 01:30:36 +0000
commitdfd868ecf9e37a5e6954a073c3ba43a970f7ca54 (patch)
tree3c85775253afaa6c43148a8da46fa8a7803de62e /lib/Huffman.cc
parentf1eb23d8a489aa0353b68aba47c065e3206920ac (diff)
Projet quasi fini...
Diffstat (limited to 'lib/Huffman.cc')
-rw-r--r--lib/Huffman.cc31
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);
+}