c Suppose q is an instance of the Queue class and assume tha
c++:
Suppose q is an instance of the Queue class and assume that the previous array implementation is used. Also, assume that the size of the array is 5 and that it is initially empty. Show q (nbrElts, frontIndx. rearlndx and contents of the array elements) after all of the following operations have been completed, assuming the queue is empty to start with. q.enqueue(39); q.enqueue(22); item1 = q.dequeue(); q.enqueue(59); item2 = q.dequeue(); item3 = q.dequeue();Solution
Queue follows FIFO(First in first out) concept to insert and remove elements from data structure.
So First 2 enqueue will insert |39||22|| || || | in queue.
item1 will contain 22 because it was inserted before 39 and removed from queue. |39|| || || || |
59 is pushed after 39. |59||39|| || || |
item2 will get 39 and item 2 59 because remember FIFO.
After all operation all the elements are empty so nbrElts = 0. frontIndx = rearIndx = -1
