Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

7. Explain how an employee could reduce stress at work.

Answered: 1 week ago

Question

Finding and scheduling appointments with new prospective clients.

Answered: 1 week ago