Priority Queue implemented as LinkedList api class java
- From: "Michael" <mbialowas@xxxxxxx>
- Date: Mon, 13 Nov 2006 19:35:20 GMT
Hello all, its been a while. cheers to all. Anyways, I have been struggling
with what is suppose to be an "Easy" problem. Someone once told me that
things are easy only when obvious. I guess my problem then is this isn't
obvious to me. I have to implement a priority queue by means of the
LinkedList class found in the api.
I know the following:
I will have to use generics(which i will use after I get this working first
with integer data types)
When generics is in play I will have to implement the Comparable interface
with the compareTo method to compare keys.(which should be fun)
next,
I will have an Entry class as an innerclass within my Priority queue class.
I will have to print out both the key and value pairs based on minimum
key(highest priority).
However, by using the LinkedList class, I am almost certain I have to use an
iterator to step through all entries in the PQ and return the one with the
minimum key.
I guess I don't really understand how I am going to do this.
I am thinking store the first entry in a temp variable and compare the rest
of the entries with this one in regards to the key? When the minimum key is
found return the entry corresponding to it
I also tried to insert entries based on their keys into the list, however,
when I did this I got size 0 index 1000 error. Furthermore, if someone could
please lead a helping hand it would be much appreciated. I know this must
seem very trivial, but it isn't for me. At the moment I think implementing
this from scratch or with an array would have been much easier.
Thanks Mike
.
- Follow-Ups:
- Re: Priority Queue implemented as LinkedList api class java
- From: not
- Re: Priority Queue implemented as LinkedList api class java
- From: Patricia Shanahan
- Re: Priority Queue implemented as LinkedList api class java
- Prev by Date: Re: classpath for web-application.
- Next by Date: Re: Help converting a string
- Previous by thread: Sorting objects
- Next by thread: Re: Priority Queue implemented as LinkedList api class java
- Index(es):
Relevant Pages
|