I have tried a few different things to try to get this error to go away. I know it is a problem with the type of data that I am trying to pass but don't see why. Any help is appreciated.
error:
File: H:\Data Structures\HW7\heapSortImplementation.java [line: 24]
Error: pqInsert(SearchKeys.KeyedItem) in PriorityQueues.PriorityQueue cannot be applied to (double)
here is the code for the searchkeyCode:public double makeHeap() { PriorityQueue prq = new PriorityQueue(); FileReader freader = new FileReader("hw7input.txt"); BufferedReader inputFile = new BufferedReader(freader); input = inputFile.readLine(); double dinput = Double.parseDouble(input); while(input != null) { prq.pqInsert(dinput);//this is the line the error is on input = inputFile.readLine(); dinput = Double.parseDouble(input); } inputFile.close(); while(!prq.pqIsEmpty()) { prq.pqDelete(); } }
This is from the PriorityQueue classCode:package SearchKeys; public abstract class KeyedItem { private Comparable searchKey; public KeyedItem(Comparable key) { searchKey = key; }//end constructor public Comparable getKey() { return searchKey; }//end getKey }//end KeyedItem
This is the method called in the the above methodCode:public void pqInsert(KeyedItem newItem) throws PQueueException { try { h.heapInsert(newItem); }//end try catch(HeapException e) { throw new PQueueException("PQueueException: Priority queue full"); }//end catch }//end pqInsert
Code:public void heapInsert(KeyedItem newItem) throws HeapException { //inserts an item into a heap //Pre-condition: newItem is the item to be inserted //Post-condition: if the heap was not full, newITem is in its proper position; otherwise HeapException is thrown if(size < MAX_HEAP) { //place the new item at the end of the heap items[size] = newItem; //trickle new item up to its proper position int place = size; int parent = (place - 1) / 2; while((parent >= 0) && (items[place].getKey().compareTo(items[parent].getKey())) < 0) { //swap items[place and items[parent] KeyedItem temp = items[parent]; items[parent] = items[place]; items[place] = temp; place = parent; parent = (place - 1) / 2; }//end while ++size; }//end if else { throw new HeapException("HeapException: Heap full"); }//end else }//end heapInsert


Reply With Quote


Bookmarks