Tree: Huffman Decoding

  • + 0 comments

    C++

    void decode_huff(node * root, string s) {
        
        node* curr=root;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]=='0')
                curr=curr->left;
            else
                curr=curr->right;
        
            if(curr->left==NULL && curr->right==NULL)
            {
                cout<<curr->data;
                curr=root;
            }
        }
    }