Page 1 of 1
Posted: Fri Aug 01, 2008 11:33 pm
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.
Posted: Sat Aug 02, 2008 4:14 am
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.