Bill
Bill

Reputation: 145

What am I doing wrong with the TreeMap<node>?

I am trying to write a program that will utilize the Huffman code. However, when I use the tree set, it wants the parameters of "Char, Integer". I want it to take in a "String, Integer" parameter. What can I do to fix this?

   private static void processFile(HashMap<String,Integer> freq)
  {
    TreeSet<Node> trees = new TreeSet<Node>();  

    for (Map.Entry<String, Integer> entry : freq.entrySet()) {
      String key = entry.getKey();
      Integer value = entry.getValue();

      if (value > 0)
      {
        Node n = new Node(key, value);
        trees.add(n);
      }
    }

Upvotes: 0

Views: 361

Answers (1)

Mordechai
Mordechai

Reputation: 16234

Change:

Node n = new Node(key, value);

to:

Node n = new Node(key.charAt(0), value);

I assume that this happens because the Node constructor requires a char not string.

Upvotes: 1

Related Questions