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)
Code:
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();
}
}
here is the code for the searchkey
Code:
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
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
11-28-2005, 08:23 PM
nspils
your KeyedItem class is abstract. Are you creating a class which inherits from this abstract class and implements the methods of this class at some point? If so, your "KeyedItem" object should be constructed in the child class ... Otherwise, I am surprised you aren't getting other errors ...