After doing some digging here is what I understood-
Java default Priority Queue is a min heap but Scala default Priority Queue is a max heap. Is this correct? Why is the implementation different in scala, it just causes more confusion in my opinion.
The Java PriorityQueue
(see docs ) defines the highest-priority item to be the one with the lowest sorting order, so a min-heap is the logical choice of data structure.
The Scala PriorityQueue
(see docs ) apparently defines the highest-priority item to be the highest-sorting , so a max-heap is the logical choice of data structure.
If you're asking why it is that highest priority means lowest-sorting in Java and highest-sorting is Scala, only the developers of the respective language libraries can answer that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.