Tree: Huffman Decoding

  • + 0 comments
    void decode(String s, Node root) {
            String word = "";
            Node location = root;
            for(char i: s.toCharArray()){
           if(i == '0'){
            if (location.left.left ==null){
                word+=location.left.data;
                location = root;
            }else{
            location = location.left;
            }
           }
           else if(i=='1'){
            if (location.right.right ==null){
                word+=location.right.data;
                location = root;
            }else{
            location = location.right;
            }
           }
           } 
           System.out.print(word);