Question: Design a class named Queue for storing integers. Like a stack, a queue holds elements. But in a queue, the elements are retrieved in a

 Design a class named Queue for storing integers. Like a stack,

Design a class named Queue for storing integers. Like a stack, a queue holds elements. But in a queue, the elements are retrieved in a first-in first-out fashion. The class contains: 1. An int[] data field named elements that stores the int values in the queue. 2. A data field named size that stores the number of elements in the queue. 3. A constructor that creates a Queue object with default capacity 8. 4. The method enqueue(int v) that adds v into the queue. 5. The method dequeue that removes and returns the element from the queue. 6. The method empty that returns true if the queue is empty. 7. The method getSize() that returns the size of the queue. Implement the class with the initial array size set to 8. The array size will be doubled once the number of elements exceeds the size. After an element is removed from the beginning of the array, you need to shift all the elements in the array one position to the left. Write a test program that adds 20 numbers from 1 to 20 into the queue then removes these numbers and displays them

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!