From dfd868ecf9e37a5e6954a073c3ba43a970f7ca54 Mon Sep 17 00:00:00 2001 From: Pixel <> Date: Mon, 5 Mar 2001 01:30:36 +0000 Subject: Projet quasi fini... --- src/main.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main.cc (limited to 'src/main.cc') diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..520f6ec --- /dev/null +++ b/src/main.cc @@ -0,0 +1,54 @@ +#include +#include +#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; +} -- cgit v1.2.3