For a queue, if we enqueue 1, 2, 3, 4, 5 and then dequeue five times, give the order of the elements dequeued from the queue.
Answer:
enqueue is used to add an item to queue
dequeue is used to remove an item from queue
When we enqueue 1, 2, 3, 4, 5 then items will be stored in queue like below
enqueue - 5 4 3 2 1 - dequeue
When we dequeue five times, the below is the order oof the elements dequeued from the queue
1 2 3 4 5
First 1 will be dequeued then 2 then 3 then 4 then 5
Because Queue is a liner data structure and it follows FIFO or LILO. it means First In First Out or Lasst In Last Out
Get Answers For Free
Most questions answered within 1 hours.