File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes priority queue doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "priority queue doubt" Watch "priority queue doubt" New topic
Author

priority queue doubt

aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111

Priority queue




Adding
0
2
1
5
3
4
after polling
0
1
2
3
4
5
why the output for adding is 0 2 1 5 3 4?(what order it is?).
I guess while adding/offering it has to be in sort order.

or poll() does the sort order and removes the highest priority element.
correct me!

Thanks
samura

aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111


public PriorityQueue(int initialCapacity,
Comparator<? super E> comparator)

what is the initialCapacity?
The API says it's the initialCapacity for the pq1(reference of
priorityqueue)
priorityQueue pq1 = new PriorityQueue(10,pqs)
what it does here? by giving the value 10..


I am little confused with this


Prasanna Rajaperumal
Greenhorn

Joined: Aug 28, 2007
Posts: 9
Hi,

Good Reason to be confused. Priority queue is implemented as Heap data structure. I do not know the exact details of the implementation. But with a min heap structure only one thing is assured, root has the minimum.

So after you poll the order you get 1, 2, 3, 4, 5 is pure coincidence. It could have been in any order with 1 as the root (first element).

Still confusing
1. read about heaps
2. Read how heaps are impemented in a queue
3. Look at priorityqueue fixup method.

0 will be polled out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: priority queue doubt
 
Similar Threads
doubt priorityqueue
doubt in offer()
Priority queue
Priority Queue Ordering
Priority queue