Skip to main contentSkip to solution

Identify the task performed by the given function.

def f1(myQueue):

if isEmpty(myQueue):

print('Queue is empty')

return None

else:

return myQueue[0]

Solution

✅ Correct Option: 2

The function first checks whether the queue is empty. If it is, it prints a message and returns None. Otherwise it returns myQueue[0], the front element, without removing it. This is the peek (front) operation of a queue.


Option 1: deleting the front element (dequeue) would need myQueue.pop(0), which removes the element. Here the element only is returned.

Option 3: insertion (enqueue) would use append(), which this function does not call.

Option 4: displaying all elements would need a loop or a print of the whole list. This function returns a single element.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question