Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using an Array of initial size of five (5) for storage, start with the following generic class declaration for QueueBox: public class QueueBox { private

Using an Array of initial size of five (5) for storage, start with the following generic class declaration for QueueBox:

public class QueueBox { private E[] elements = (E[])( new Object[5] ); private int front_idx = 0; private int rear_idx = 0; private int count = 0; }

Hint: use the count variable to keep track of how many elements are in the queue (increment count when enqueing and decrement when dequeing). Makes it a lot easier to determine if the array is full and for the other functions as well.

Of course you may add or modify variables to this class BUT you MUST use a GENERIC array of initial size 5 and your queue MUST be a circular queue. Ensure your QueueBox can do the following:

boolean add(E e) Adds e to the queue (enqueue). returns true. Throws NullPointerException if e is null.

E remove() Removes element in the front of the queue (dequeue) and returns it. NoSuchElementException is thrown if this queue is empty

E element() Retrieves, but does not remove, the head of the queue. Throws NoSuchElementException - if the queue is empty.

boolean isEmpty() returns true if queue is empty.

int size() returns number of elements held in the queue.

Create a driver class QueueBoxDriver that creates an instance of QueueBox then fills it with 60,000 integers numbered from 0 to 59999 (in that order). Your QueueBox must be able to resize itself (double in size) when needed to accomodate. Everytime your queue auto-resizes it must display that it has done so (see output below). After you create your queue and populate it, dequeue the first 50000 elements.

Now dequeue the remaining 10000 elements and display them to the screen. Continue until the queue is empty. Your output should look as close as possible to this:

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions