• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating class to implement PriorityQueue using binary Heap. Java  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in urgent need of help, in 2 hours my homework will be due and I haven't got the slightest clue how to fix everything
Please, if anybody can help me finish this, I am seriously begging you.
this is the HeapPriorityQueue class I have so far:


this should implement



this wil be the Driver class



but I am getting these Problems:
Description Resource Path Location Type
Java Problem
Bound mismatch: The type String is not a valid substitute for the bounded parameter <V extends Comparable<K>> of the type HeapPriorityQueue<K,V> HeapPriorityQueueDriver.java /MP7/src/simon/mp7 line 6 Java Problem
Bound mismatch: The type K is not a valid substitute for the bounded parameter <K extends Comparable<K>> of the type Entry<K,V> HeapPriorityQueue.java /MP7/src/simon/mp7 line 199 Java Problem
The serializable class UnderflowException does not declare a static final serialVersionUID field of type long UnderflowException.java /test/src/test line 8 Java Problem
Bound mismatch: The type K is not a valid substitute for the bounded parameter <K extends Comparable<K>> of the type Entry<K,V> HeapPriorityQueue.java /MP7/src/simon/mp7 line 193 Java Problem
Bound mismatch: The type K is not a valid substitute for the bounded parameter <K extends Comparable<K>> of the type Entry<K,V> HeapPriorityQueue.java /MP7/src/simon/mp7 line 187 Java Problem
The method compareTo(K) is undefined for the type K HeapPriorityQueue.java /MP7/src/simon/mp7 line 126 Java Problem
The method compareTo(K) is undefined for the type K HeapPriorityQueue.java /MP7/src/simon/mp7 line 104 Java Problem
The method compareTo(K) is undefined for the type K HeapPriorityQueue.java /MP7/src/simon/mp7 line 100 Java Problem
Bound mismatch: The type K is not a valid substitute for the bounded parameter <K extends Comparable<K>> of the type PriorityQueue<K,V> HeapPriorityQueue.java /MP7/src/simon/mp7 line 5 Java Problem


and this Console Message:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Bound mismatch: The type String is not a valid substitute for the bounded parameter <V extends Comparable<K>> of the type HeapPriorityQueue<K,V>

at simon.mp7.HeapPriorityQueueDriver.main(HeapPriorityQueueDriver.java:6)


 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have this as the class definition:
public class HeapPriorityQueue<K,V extends Comparable<K>> implements PriorityQueue<K, V>
The interface is this:
public interface PriorityQueue<K extends Comparable<K>,V>
And you are creating an instance like this:
PriorityQueue<Integer, String> queue = new HeapPriorityQueue<Integer, String>()

Do you see how your class definition says "A HeapPriorityQueue with keys of some type K, and whose value, V, is a Comparable for the Key". Does that make sense? Note it doesn't follow the interface which says "A PriorityQueue with keys of some type K which must be Comparable to Ks, and whose value, V, is of some type."

Then look at your instance. You try to make a HeapPriorityQueue whose K is Integer, and the rule for V is that it must be Comparable<Integer>, but you put a String in there. Is a String Comparable<Integer>?
 
Simon Go
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir Steve I have fixed that problem.
How can I implement insert(K key, V value)?
it returns null at the moment, I am not sure how I am to get around making the program get the value K so that it would sort
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Therein lies your homework, yes? Why don't you try it out. Use pencil and paper to write the steps out in English, and when you are sure about the sequence, turn it to Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!