• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

PriorityQueue Issue

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PriorityQueue (todo list),


Case 1:

Case 2:


Question:
Why does output from case 1 and case 2 mismatch?
Case 2, output is ordered on behalf of default (Comparable),
or custom(Comparator) todo way.

What way case 1 is following in printing?

Thanks,

cmbhatt
[ April 15, 2007: Message edited by: Chandra Bhatt ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Answer!

:roll:



cmbhatt
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

API says about PriorityQueue:

The queue retrieval operations poll, remove, peek, and element access the element at the head of the queue.
(...)
The Iterator provided in method iterator() is not guaranteed to traverse the elements of the PriorityQueue in any particular order. If you need ordered traversal, consider using Arrays.sort(pq.toArray()).


The toString method of PQ uses the iterator, I guess.
The fact that PriorityQueue is ordered, but the iterator has no order frequently results in some confusion...
Can we call this a bug?

Example:

prints:



Yours,
Bu.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Burkhard,

I was lazy enough to give complete code! What you did greatly
here.

Your explanation is quite nice regarding the confusing issues.




Thanks,
cmbhatt
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,

Burkhard Hassel is right the method uses iterator. this is the code:


you can download from SUN the src and check the API code for more info about API methods.

Cheers.
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic