Question: PQ is Priority Queue .. public class LinkedPQ { private int size; private PQNode head; /* tail is of no use here. */ public LinkedPQ()
PQ is Priority Queue ..
public class LinkedPQ {
private int size;
private PQNode head;
/* tail is of no use here. */
public LinkedPQ() {
head = null;
size = 0;
}
public int length (){
return size;
}
public boolean full () {
return false;
}
public void enqueue(T e, int pty) {
PQNode tmp = new PQNode(e, pty);
if((size == 0) || (pty > head.priority)) {
tmp.next = head;
head = tmp;
}
else {
PQNode p = head;
PQNode q = null;
while((p != null) && (pty
q = p;
p = p.next;
}
tmp.next = p;
q.next = tmp;
}
size++;
}
public PQElement serve(){
PQNode node = head;
PQElement pqe=new PQElement(node.data,node.p);
head = head.next;
size--;
return pqe;
}
public class PQElement
{
public T data;
public Priority p;
public PQElement(T e, Priority pr){
data=e;
p=pr;
}
this code is the lecture implementation
1. Write a linked implementation of the ADT PQueue where the elements are kept in their order of insertion. What is the performance of the methods enqueue and serve in this case? Compare this implementation to the one seen in lecture. Which implementation is better (justify your answer)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
