algorithm-archive
algorithm-archive copied to clipboard
Kotlin huffman
This code doesn't work for a string of one unique character multiple times. I don't know Kotlin at all but I have a fix you can look at and improve on.
if (priorityQueue.size == 1) {
val left = priorityQueue.remove()
val right = Leaf(0, '\u0000')
root = Branch(left, right)
} else {
root = priorityQueue.remove() as? Branch ?: error("No support for string of one unique letter")
}
I'm not sure how to get right to be a null object but this will do.
I just saw this. Why are these changes on top of https://github.com/algorithm-archivists/algorithm-archive/pull/640?
[lang: kotlin]