1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include "basic_hufftree.hpp"
typedef basic_hufftree<unsigned char> hufftree;
#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
int main()
{
using namespace std;
const unsigned char str[] = "this is an example of a huffman tree";
vector< pair<list<int>, unsigned char> > char_table;
vector< pair<list<int>, unsigned char> >::const_iterator cit;
hufftree htree(hufftree::create_tree(str, sizeof(str)-1));
char_table = htree.char_table();
for (cit = char_table.begin(); cit != char_table.end(); cit++) {
cout << "(" << cit->second << ", ";
copy(cit->first.begin(), cit->first.end(),
ostream_iterator<int>(cout,""));
cout << ")\n";
}
}
|
(a, 111)
(e, 110)
(t, 1011)
(h, 1010)
(i, 1001)
(s, 1000)
(n, 0111)
(m, 0110)
(x, 01011)
(p, 01010)
(l, 01001)
(o, 01000)
(u, 00111)
(r, 00110)
(f, 0010)
( , 000) |