Tree: Huffman Decoding

  • + 0 comments
    void decode_huff(node * root, string s) {
        node* curr = root;
        string print;
        while(!s.empty())
        {
            if(curr->data != '\0')
            {
                print += curr->data;
                curr = root;
                continue;
            }
            if(s.front() == '0')
            {
                curr = curr->left;
            }
            else
            {
                curr = curr->right;
            }
            s.erase(0, 1);
        }
        print += curr->data;
        cout << print;
    }