Question
Please help!!! I am a little lost with this Java code! class Queue { private int maxSize; private long[] queArray; private int front; private int
Please help!!! I am a little lost with this Java code!
class Queue { private int maxSize; private long[] queArray; private int front; private int rear; private int nItems;
public Queue(int s) { maxSize = s; queArray = new long[maxSize]; front = 0; rear = -1; nItems = 0; }
public void insert(long j) { if (rear == maxSize -1) rear = -1; queArray[++rear] = j; nItems++; }
public long remove() { long temp = queArray[front++]; if (front == maxSize) front = 0; nItems --; return temp; }
public long peekFront() { return queArray[front]; }
public boolean isEmpty() { return(nItems==0); }
public boolean isFull() { return(nItems==maxSize); }
public int size() { return nItems; }
}
class QueueApp { public static void main(String[] args) { Queue theQueue = new Queue(5); theQueue.insert(10); theQueue.insert(20); theQueue.insert(30); theQueue.insert(40); theQueue.remove(); theQueue.remove(); theQueue.remove(); theQueue.insert(50); theQueue.insert(60); theQueue.insert(70); theQueue.insert(80); while( !theQueue.isEmpty() ) { long n = theQueue.remove(); System.out.print(n); System.out.print(" "); } System.out.println(""); } }
-------------------------------
I can somewhat understand, but would like help rewritting and understanding it better as a dequeue under the following instructions.
-> Dequeue needs to support wraparound at the end of the array, as queues do, and should include the following methods: -> insertFront(), removeFront(): insert and remove element into the Dequeue -> insertRear(), removeRear(): insert and remove element into the Dequeue -> isEmpty(): if the Dequeue is empty o isFull(): if the Dequeue is full -> size(): return the number of items in queue. -> display(): display all the element from Front to Rear -> Required to have three objects to show your deque ADT used as a stack, queue, and dequeue.
Step 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