I am not sure how to proceed with adding element to the Priority Queue. I don't want code to be spoon feed to me, can someone just explain to me how to use interface passed to another interface as parameter and a class implementing one of its method. Please give me pointers, I will look it up and learn how to implement this code.
QueueItem class
public interface QueueItem
{
/**
* Returns the priority of this item. The priority is guaranteed to be
* between 0 - 100, where 0 is lowest and 100 is highest priority.
*/
public int priority();
}
PriorityQueue class
public interface PriorityQueue
{
/**
* Inserts a queue item into the priority queue.
*/
public void insert(QueueItem q);
/**
* Returns the item with the highest priority.
*/
public QueueItem next();
}
QuickInsertQueue class
public class QuickInsertQueue implements PriorityQueue {
@Override
public void insert(QueueItem q) {
// TODO Auto-generated method stub
}
@Override
public QueueItem next() {
// TODO Auto-generated method stub
return null;
}
}
I have to Write a QuickInsertQueue
class that implements the PriorityQueue
interface having insert()
method O(1).