import java.util.Iterator; import java.util.LinkedList; import java.util.ListIterator; /* * This class implements a priority queue using a linked
Question:
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
/*
* This class implements a priority queue using a linked list. The queue can hold a reference to
* any object whose class implements the Sizeable interface. The getSize() method is used to
* determine the priority of an object and where it should be placed in the queue.
*/
public class MyPriorityQueue
{
LinkedList
public void add(Sizeable o)
{
//-----------Start below here. To do: approximate lines of code = 8
// add an object o to the queue based on its priority.
// The priority is determined by calling the getSize() method of the object.
// The object should be added such that the size of the objects (i.e. their priority)
// is from largest to smallest. Hint: use an iterator. Also, handle the special case
// when the queue is empty
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
public Sizeable remove()
{
//-----------Start below here. To do: approximate lines of code = 1
// remove an object from the front of the queue
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
public boolean isEmpty()
{
return queue.isEmpty();
}
}
Data Structures and Algorithm Analysis in Java
ISBN: 978-0132576277
3rd edition
Authors: Mark A. Weiss