You are viewing a single comment's thread. Return to all comments →
void iter(node * root, std::string key, std::map<std::string, std::string> &dictionary){ if(root == NULL){ return; } if(root->data != '\0') { std::string s{root->data}; dictionary[key] = s; } iter(root->left, key+"0", dictionary); iter(root->right, key+"1", dictionary); } void decode_huff(node * root, string s) { std::map<std::string, std::string> dictionary; std::string binary = ""; iter(root, binary, dictionary); binary=""; for (char c : s){ std::string str{c}; binary = binary+str; if (dictionary.find(binary) != dictionary.end()) { std::cout <<dictionary[binary]; binary=""; } } }
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 →