Tree: Huffman Decoding

  • + 0 comments

    C++ 14 solution:

    void decode_huff(node * root, string s) {
         if(root == NULL || s.empty() || s == ""){
            cout<<"";
            return;
        }
        
        auto temp = root;
        for(auto c : s){
            temp = c == '0' ? temp->left : temp->right;                
            
            if(temp && temp->data){
                cout<<temp->data;
                temp = root;
            }
        }    
    }