#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; }