A queue serves its elements in their order of arrival. Write a class IntQueue and a public class IntQueueApp.
IntQueue hides an int[] elements and a counter size.
- Three constructors:
IntQueue()(capacity 4, throughthis(4)),IntQueue(int capacity)and the copy constructorIntQueue(IntQueue other), which must give the new queue its own array. enqueue(int v)adds at the end; when the array is full, it is replaced by one twice as long.dequeue()removes and returns the first element and shifts the others one place forward.peek(),isEmpty(),getSize(),getCapacity().
main reads the commands add 5, remove, first, size until the end of the input. Then it makes a copy of the queue, empties the copy while printing it, and shows that the original is intact. For the input
add 5
add 8
add 2
size
remove
first
add 9
add 4
add 7
size
the program prints
Size 3, capacity 4
Removed 5
First is 8
Size 5, capacity 8
Remaining, first to last: 8 2 9 4 7
Original still holds 5 element(s); the copy holds 0