You are viewing a single comment's thread. Return to all comments →
C++ code only:
Non recursive:
void decode_huff(node * root, string s){ node *pRoot = root; int i = 0; while(s[i] != '\0'){ if(s[i] == '0') pRoot = pRoot->left; else if(s[i] == '1') pRoot = pRoot->right; if(pRoot->data != '\0'){ cout << pRoot->data; pRoot = root; } ++i; } }
Recursive :
void decode_huff(node * root, string s){ node *pRoot = root; int len = s.size(); int i = 0; while(i <= len){ if(s[i] == '0') pRoot = pRoot->left; else if(s[i] == '1') pRoot = pRoot->right; if(pRoot->data != '\0'){ cout << pRoot->data; ++i; break; } ++i; } if(s[i] != '\0') decode_huff(root, s.substr(i, len)); }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Huffman Decoding
You are viewing a single comment's thread. Return to all comments →
C++ code only:
Non recursive:
Recursive :