blob: 4f68852e1da5f0678dd7bdf723739cbdf17b3b18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#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);
}
|