33 ~Tree() { destroy(root); }
36 friend void decoder();
37 friend void encoder();
39 void destroy(Node *N) {
48 unsigned int get_freq()
const {
return root->freq; }
50 unsigned char get_char()
const {
return root->ch; }
52 void set_freq(
unsigned int f) { root->freq = f; }
54 void set_char(
unsigned char c) { root->ch = c; }
91 bool operator==(
const Tree &T)
const {
return (root->freq == T.root->freq); }
97 bool operator!=(
const Tree &T)
const {
return (root->freq != T.root->freq); }
129 void huffman(Node *N,
unsigned char c,
string str,
string &s)
const {
131 if (!N->left && !N->right && N->ch == c) {
134 huffman(N->left, c, str +
"0", s);
135 huffman(N->right, c, str +
"1", s);
148 if (!N->left && !N->right) {
149 cout <<
print_char(N) <<
" : " << N->freq <<
" : " << str
169 for (
unsigned i = 0; i < str.size(); ++i) {
180 if (!curr->left && !curr->right) {
197 if (!N->left && !N->right) {
198 unsigned char c = N->ch;
200 if (iscntrl(c) || c == 32) {
201 char *temp_char =
new char;
202 for (
int i = 0; i < 3; ++i) {
203 sprintf(temp_char,
"%i", c % 8);
206 str = (*temp_char) + str;
Definition huffmantree.h:9
bool get_huf_char(string str, unsigned char &c) const
Definition huffmantree.h:166
void set_left(Node *N)
Definition huffmantree.h:76
Node * get_right() const
Definition huffmantree.h:69
void set_right(Node *N)
Definition huffmantree.h:83
bool operator==(const Tree &T) const
Definition huffmantree.h:91
bool operator>=(const Tree &T) const
Definition huffmantree.h:120
bool operator<(const Tree &T) const
Definition huffmantree.h:103
Node * get_root() const
Definition huffmantree.h:59
void huffman_list(Node *N, string str) const
Definition huffmantree.h:146
bool operator<=(const Tree &T) const
Definition huffmantree.h:109
void huffman(Node *N, unsigned char c, string str, string &s) const
Definition huffmantree.h:129
Node * get_left() const
Definition huffmantree.h:64
string print_char(Node *N) const
Definition huffmantree.h:194
bool operator!=(const Tree &T) const
Definition huffmantree.h:97
bool operator>(const Tree &T) const
Definition huffmantree.h:114