Tree: Huffman Decoding

Sort by

recency

|

19 Discussions

|

  • + 0 comments

    C++

    void decode_huff(node * root, string s) 
    {
        string result = "";
        node * currNode = root;
        auto it = s.begin();
        
        while (it != s.end())
        {
            // Read s and traverse until we reach a leaf.
            while (currNode->data == '\0')
            {
                if (*it == '0')
                {
                    currNode = currNode->left;
                }
                else if (*it == '1')
                {
                    currNode = currNode->right;
                }
                else 
                {
                    cout << "Error";
                }
                
                it++;
            }
            
            // Leaf. Get letter and reset.
            result += currNode->data;
            currNode = root;
        }
        
        cout << result;
    }
    
  • + 0 comments

    Here is Hackerrank Tree huffman decoding problem solution in Python Java c++ c and javascript

  • + 0 comments

    There is something wrong with the problem as my solution just return the same input and it will work javascript

    function processData(input) {
        //Enter your code here
        console.log(input);
    } 
    
  • + 0 comments

    There is something wrong with the problem as my solution just return the same input and it will work javascript function processData(input) { //Enter your code here console.log(input); }

  • + 0 comments

    JAVA

    void decode(String s, Node root) {        
        Node current = root;
        for (char c : s.toCharArray()) {           
            if (c == '0') {
                current = current.left;
            } else {
                current = current.right;
            }
            
            if (current != null && current.data != '\0') {
                System.out.print(current.data);
                current = root;
            }
            
        }
    }