Question
Please help me complete the java methods in the picture. Here is my code so far: class DynamicQueue{ private DynamicNode front, rear; public DynamicQueue(){ front=rear=null;
Please help me complete the java methods in the picture.
Here is my code so far:
class DynamicQueue{ private DynamicNode front, rear; public DynamicQueue(){ front=rear=null; } public boolean empty(){ return (front==null); } }
public void insert(Object x){ DynamicNode p=new DynamicNode(x,null); if(empty()) front=rear=p; else rear.setNext(p); rear=p; } public Object remove(){ if(empty()){ System.out.println(Queue underflow); System.exit(1); } DynamicNode p=front; Object temp=p.getInfo(); front=p.getNext(); if(front==null) rear=null; return temp; }
Here is the image of what needs to be done please:
following this will cause a zero grade for the operation Description: In this assignment, you will implement N dynamic priority queues. Let us first look at a single queue. Your program is given a sequence of objects, for example: a, b, w, a, x, s, . The queue maintains numElements such objects, so that the first (front) is the oldest in the sequence, and the last (rear) is the most recent in the sequence. When the queue is full, the oldest (front) is deleted, so that the new object can be inserted (in rear). If an object that is already in the queue is seen again, it becomes the most recent (it is moved to the rear). This way, the queue is maintained ordered by the object's place in the sequence (last node - most recently referenced first node least recently referenced) The queue wil be implemented using a single-linked list (DynamicNode, rear and front pointers so it should be similar to DynamicQueue from slides "Lecture 5-Queues"). Elements are inserted at the rear, deletion is explained in the following paragraphs. To implement the queue, you CANNOT use: array, or any available classes such as JDK's Queue, LinkedList, or PriorityQueue The N queues are maintained in a 1-D array. Assuming your queue class is DynamicQueue, below is an example for the array of queues DynamicQueuel] queues = new DynamicQueue[n]; Your program must set (hardcode) these: the number of queues (N=length of the array), and the max number of elements in each queue (QUEUESIZE) Your program reads a file that contains a sequence ofStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started