Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA Implement a queue using an array in class of type String. Make your stack size 5 when you test it, but do not

IN JAVA

Implement a queue using an array in class of type String.

image text in transcribed

Make your stack size 5 when you test it, but do not hardcode this throughout! You should be able to change the size for testing purposes with the change of one variable.

Call your queue class queue.

DO NOT use Queue class defined in your programming language's libraries, you will receive ZERO POINTS.

An array will need to handle wrap around. Think about removing from the front of a full queue. The queue will not be empty, but the items will be in indexes 1, 2, 3 and 4 and index 0 will be free and the queue is not longer full. It would be inefficient to move all elements up in the array. However, the head is now at 1 and the tail is at 4, so you would add the 5th item in index 0.
  • queue() creates an empty queue, queue is new and empty.
  • enqueue(item) adds a new item to the queue, queue is modified.
  • dequeue() removes and returns an item, queue is modified.
  • isEmpty() returns a boolean and tests for an empty queue, queue is not modified.
  • isFull() returns a boolean and tests for a full queue, queue is not modified.
  • size() returns the int size of the queue, queue is not modified
  • print() prints the queue from front to rear, queue is not modified.
  • peek() prints the front element, queue is not modified.

Driver, Named QueueDriverYourLastName, should print the results of the following

  • enqueue("dog")
  • enqueue("cat")
  • enqueue("mouse")
  • enqueue("pig")
  • enqueue("bird")
  • size()
  • enqueue("puppy")
  • size()
  • dequeue()
  • dequeue()
  • size()
  • dequeue()
  • peek()
  • dequeue()
  • dequeue()
  • size()
  • isEmpty()
front rear 726 91 0 1 2 3 4 5 Queue

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

Step: 3

blur-text-image

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions