What operation on a queue is performed using the following code segment?
def op(myqueue):
if not(isEmpty(myqueue)):
return myqueue.pop(0)
else:
print ("Queue Empty")
What operation on a queue is performed using the following code segment?
def op(myqueue):
if not(isEmpty(myqueue)):
return myqueue.pop(0)
else:
print ("Queue Empty")
Solution
✅ Correct Option: 2
The code first checks that the queue is not empty. It then removes and returns the element at index 0, which is the front of the queue. Removing from the front is the dequeue operation, and it follows the FIFO (First In, First Out) rule. If the queue is empty, it prints "Queue Empty" (underflow).
Option 1: enqueue adds an element at the rear, using append(), not pop(0).
Option 4: peek/peep only reads the front element without removing it, but pop(0) removes it.
Related questions:
2026: 19 May Shift 1
2026: 29 May Shift 2
2026: 18 May Shift 2