+ 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
2 Respuestas
+ 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.
+ 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..👍