blob: 520f6ecc0d56f016b736ea828f916202d6af1ef2 (
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "BHeap.h"
#include "FHeap.h"
#include "BinHeap.h"
#include "PLList.h"
#include "Huffman.h"
void exception(int e, char *msg)
{
fprintf(stderr, "%s\n", msg);
exit(-1);
}
PriorityList *newlist(void)
{
return new BinHeap;
}
void Count(FILE * strm, PriorityList * P)
{
int tab[256], i;
char *t;
for (i = 0; i < 256; i++) {
tab[i] = 0;
}
while ((i = getc(strm)) != EOF) {
tab[i]++;
}
for (i = 0; i < 256; i++) {
if (tab[i]) {
t = (char *) malloc(2);
t[0] = i;
t[1] = 0;
HInsert(P, tab[i], t);
}
}
}
int main(int argc, char **argv)
{
PriorityList *P = newlist();
HTree *H;
Count(stdin, P);
H = Coder(P);
H->Trace(cout);
return 0;
}
|