Alan Lee
05/03/2022, 6:29 AMPriorityQueue
and compareBy
?
fun testPQ(words: Array<String>) {
val heap = PriorityQueue<String>(
compareBy<String>{ it.length }
)
words.forEach {
heap.offer(it)
}
println(heap)
}
fun main() {
val input = arrayOf("the","day","is","sunny","tha","a","def","sunny","as","by")
testPQ(input)
}
The result I see is [a, as, is, day, by, the, def, sunny, sunny, tha]
by
and tha
seems to be out of order.ephemient
05/03/2022, 6:41 AMAlan Lee
05/03/2022, 7:35 AM