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

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 queue = new 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();
}
}

Step by Step Solution

3.46 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

MyPriorityQueuejava import javautilIterator import javautilLinkedList import javautilListI... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

608c00a38253b_208363.pdf

180 KBs PDF File

Word file Icon

608c00a38253b_208363.docx

120 KBs Word File

Students Have Also Explored These Related Programming Questions!