Question: Write the class LinkedPriorityQueue that extends Comparable and Implements PriorityQueueInterface THIS IS THE PriorityQueueInterface class that is given: package edu.iastate.cs228.hw05; /** An interface for the

Write the class LinkedPriorityQueue that extends Comparable and Implements PriorityQueueInterface

THIS IS THE PriorityQueueInterface class that is given:

package edu.iastate.cs228.hw05; /** An interface for the ADT priority queue. @author Frank M. Carrano @author Timothy M. Henry @version 4.0 */ public interface PriorityQueueInterface> { /** Adds a new entry to this priority queue. @param newEntry An object to be added. */ public void add(T newEntry);

/** Removes and returns the entry having the highest priority. @return Either the object having the highest priority or, if the priority queue is empty before the operation, null. */ public T remove();

/** Retrieves the entry having the highest priority. @return Either the object having the highest priority or, if the priority queue is empty, null. */ public T peek();

/** Detects whether this priority queue is empty. @return True if the priority queue is empty, or false otherwise. */ public boolean isEmpty();

/** Gets the size of this priority queue. @return The number of entries currently in the priority queue. */ public int getSize();

/** Removes all entries from this priority queue. */ public void clear(); } // end PriorityQueueInterface

THIS IS THE LinkedPriorityQueue skeleton class that is given:

public final class LinkedPriorityQueue>

implements PriorityQueueInterface

{

private Node firstNode; // Reference to first node of chain and the front

// of the priority queue, which has the highest priority

private int length; // Number of entries in chain

public LinkedPriorityQueue()

{

firstNode = null;

length = 0;

}

public void add(T newEntry)

{

//TODO

return;

}

public T remove()

{

//TODO

return null;

}

public T peek()

{

//TODO

return null;

}

/**

* If queue is empty returns [].

* Else, returns as [1, 2, 3]

* Important: note a comma and single space before every

* item except the last, and after last there is no space.

* In both cases before and after square brackets there

* is no space.

*

*/

@Override

public String toString()

{

//TODO

return null;

}

public boolean isEmpty()

{

boolean result;

if (length == 0)

{

assert firstNode == null;

result = true;

}

else

{

assert firstNode != null;

result = false;

}

return result;

}

public int getSize()

{

return length;

}

public void clear()

{

firstNode = null;

length = 0;

}

private class Node

{

private T data; // Entry in priority queue

private Node next; // Link to next node

private Node(T dataPortion)

{

data = dataPortion;

next = null;

}

private Node(T dataPortion, Node nextNode)

{

data = dataPortion;

next = nextNode;

}

private T getData()

{

return data;

}

private void setData(T newData)

{

data = newData;

}

private Node getNextNode()

{

return next;

}

private void setNextNode(Node nextNode)

{

next = nextNode;

}

}

} // end LinkedPriorityQueue

PLEASE Implement all the methods in the LinkedPriorityQueue class that have the //TODO in them. Should be the add(), remove(), peek() and toString() methods

NOTE:

1) You cannot create any additional data fields. Only use the ones provided

2) NO custom class can be used or introduced

3) NO IMPORT STATEMENTS ALLOWED

Please follow these directions and help me implment this class. Thank you very much!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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

Students Have Also Explored These Related Databases Questions!