Skip to content
Snippets Groups Projects
Commit 39f7ee17 authored by Michael Lee's avatar Michael Lee
Browse files

Fix node comparison bug in HuffmanCompressor

HuffmanCompressor.Node's compareTo method was using a method of
comparison that failed in certain cases. This update adds a more
complex, sophisticated comparison check.
parent e168c273
No related branches found
No related tags found
No related merge requests found
......@@ -107,7 +107,17 @@ public class HuffmanCompressor
}
public int compareTo(Node other) {
return this.freq - other.freq;
int result = this.freq - other.freq;
if (result != 0) {
return result;
}
if (this.value == null) {
return 1;
}
else if (other.value == null) {
return -1;
}
return this.value.compareTo(other.value);
}
}
void reset() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment