Which of the following function can be used to insert a new element at the end of a queue?
(Assume a queue named myQueue has been created by assigning an empty list i.e., myQueue = list())
Which of the following function can be used to insert a new element at the end of a queue?
(Assume a queue named myQueue has been created by assigning an empty list i.e., myQueue = list())
Solution
✅ Correct Option: 2
A queue follows FIFO, so a new element is added at the rear (end). Since myQueue is a Python list, the list method append(element) adds an item at the end, which is exactly what enqueue needs.
Option 1: add() is a method of sets, not lists.
Option 3: push() is a common stack term, but Python lists have no such method.
Option 4: insert() needs two arguments (index and element), so insert(element) raises an error.
Related questions:
2025: 15 May Shift 2
2026: 29 May Shift 2
2026: 24 May Shift 1