For reference, I am creating a Huffman tree for an assignment in school. I have created the tree, and stored values in a map using this format:
map.put((char,string));
char: is derived by reading one character at a time from a buffered reader
string: is the “binary” code assigned to that character based on its tree placement
Now I want to produce a String of “binary” that represents my initial input from the buffered reader. How do I do this? This is what I’ve tried:
String binary = "";
int q;
while ((q = buffer.read()) != -1) {
char key = (char)q;
char value = (char)key.get();
binary += value;
}
System.out.println(binary);
shouldn’t it just be value = map.get(key) ?