You are viewing a single comment's thread. Return to all comments →
much simpler than I was anticipating :D
C++14 solution:
void decode_huff(node * root, string s) { string result; node* ptr = root; for (int i = 0; i < s.size(); ++i) { switch (s[i]) { case '0': ptr = ptr->left; break; case '1': ptr = ptr->right; break; } if (!ptr->left && !ptr->right) { result += ptr->data; ptr = root; } } cout << result << endl; }
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 →
much simpler than I was anticipating :D
C++14 solution: