-1

I have created a huffman tree, and I now need to traverse the huffman tree to decode a message. I am writing the method to traverse the huffman tree, and I am unable to access the current node of my tree, even though I passed it my tree. Any help would be appreciated - rude comments are not.

     //Code that creates huffman tree not shown
//method to find traverse at very bottom
    public static class Tree implements Comparable<Tree>{
    Node root;


public Tree(Tree t1, Tree t2){
    root = new Node();
    root.left = t1.root;
    root.right = t2.root;
    root.weight = t1.root.weight + t2.root.weight;
}

public Tree(int weight, char element){
    root = new Node(weight, element);
}

@Override
public int compareTo(Tree t){
    if(root.weight < t.root.weight){
        return 1;
    }else if(root.weight == t.root.weight){
        return 0;
    }else
        return -1;
}

public  class Node{
    char element;
    int weight;
    Node left;
    Node right;
    String code = "";

    public Node(){

    }

    public Node(int weight, char element){

        this.weight = weight;
        this.element = element;
    }

     public void findLetter(Tree tree){
    char letter;


    Node.current = root; //Red lines involving everything with Node or current from here on
    if(code[i] == 0){
        if(current.left == null){
        letter = current.element;
    }else{
        current = Node.left;

    }
}else if(code[i] == 1){
    if(current.right == null){
        letter = current.element;
    }else{
        current = Node.right;
    }
}
    System.out.printf(""+ letter);
}
  • The tree is created from a analyzing the frequency of binary characters. I did not believe that it is relevant to show all of the code that finds the frequency, and creates the tree, ect. The traversal of the tree is in the method findLetter(), at the bottom of the code. – Elisabeth Post Apr 06 '16 at 20:26

1 Answers1

1
Node.current = root;

There is no member named current in Node class. And even if it is exist current = root is the code to assign the current.

Joseph K.
  • 784
  • 1
  • 9
  • 19