Do you think a hash table is a good data structure for implementing a priority queue?
Any ideas?

Recommended Answers

All 3 Replies

If you look at the "All Known Implementing Classes:" for Interface Collection<E> you'll find a number of priority queue implementations. Which one you chose depends on your exact requirements.
If you have to build it yourself, have a look at TreeSet using a Comparator that sorts the items in priority order

Hashtable is rarely a good basis for a data structure. It's slow...

Hi as far as I know people usually use Heap to implement a priority queue because of its efficiency. The update cost of a heap is O(logn) with n is the total number of the elements in a heap. You can look at the book Introduction to Algorithms to take a quick look at Heap description and then read this implementation of heap in Java to use it:
http://www.cs.uiowa.edu/~sriram/21/spring07/code/heap.java

Hope this help, cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.