java.util.PriorityQueue...

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)

java.util.PriorityQueue...

Post by nymo »

I want a working code snippet with priority queue of java which takes a double array ... I am interested in insert and retrieval oprerations... I need to know how this class works... and I am not a Java guy. Thanks in advance.
regards,
nymo
andmej
Experienced poster
Posts: 158
Joined: Sun Feb 04, 2007 7:45 pm
Location: Medellin, Colombia

Re: java.util.PriorityQueue...

Post by andmej »

I don't understand the part of the "double array", but here's a Dijkstra implementation in Java which uses a PriorityQueue. This should work as a template. Basically what you have to do is create a class that implements interface Comparable (you should create a method called compareTo) and then create a new PriorityQueue<MyClass>. Be careful, it's a little different to C++ STL priority_queue, in the sense that in C++ the biggest element is on top of the queue, but on Java's PriorityQueue, it's the smallest element the one on top.

Here's the link: http://www.cs.purdue.edu/homes/czajkat/progchal/

Look at problem C from match 4 (Oct. 7, 2006), and look for the sample C.java solution in the zipfile.
Runtime errors in Pascal are reported as Wrong Answers by the online judge. Be careful.

Are you dreaming right now?
http://www.dreamviews.com
Post Reply

Return to “Java”