105k views
1 vote
Suppose you start with an empty queue and perform the following operations: enqueue 1, enqueue 2, dequeue, enqueue 3, enqueue 4, dequeue, enqueue 5. What are the resultant contents of the queue, from front to back?

a. 1, 2, 3, 4, 5
b. 1, 3, 5
c. 1, 2, 3
d. 3, 4, 5

User Hyperplane
by
4.9k points

1 Answer

5 votes

Answer:

The correct answer is d) 3 4 5

Explanation is given below

Step-by-step explanation:

A queue is FIFO data structure which means first in first out so when you perform operation enqueue 1, enqueue 2 it will add 1, 2 to queue when you perform dequeue it will remove front element which is 1 further when you perform enqueue 3 and enqueue 4 it will add 3 and 4 to queue and when you perform dequeue it will remove front element which is now 2 as 1 is already removed after that when you perform enqueue 5 it will add 5 to queue so now the queue is like 3 4 5.

User Roarster
by
5.0k points