[Ask] PriorityQueue on Java | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

[Ask] PriorityQueue on Java

Can you help me to explain about order sequence of PriorityQueue with simple words. cause so confuse when i try to add same elements with different input order the result is difference . please see two codes below.Exactly what is the meaning of "Priority" here? Thanks Before code 1: https://code.sololearn.com/cZYQLnwZKPtC/?ref=app code 2: https://code.sololearn.com/cLpY2kON3tuk/?ref=app

24th May 2017, 1:13 PM
DraST (dradroid.com)
DraST (dradroid.com) - avatar
2 Respostas
+ 4
Hi, PriorityQueue uses natural ordering. You can ask then why the printed result is in different order. Because it is just a toString() method so it is a mistake you tried to understand this queue using it. You should poll items from the queue: String s=null; while((s=data.poll()) != null) { System.out.println(s); } Try it on your code.
24th May 2017, 5:14 PM
TamƔs Barta
TamƔs Barta - avatar
+ 1
Thanks a lot @TamĆ”s Barta, Sorry for my mistakes to understand because i still begineršŸ˜„. but your code was solved my problem. Thanks again..šŸ‘
24th May 2017, 5:45 PM
DraST (dradroid.com)
DraST (dradroid.com) - avatar