A queue is a line of elements: new items join at the end, and the item waiting longest leaves first. This is called first-in-first-out (FIFO). A list can provide the underlying storage while queue operations give it more specific behavior. section 26.4
A grocery-store line in Python
Start with line = []. Append Ana and Bob, then pop(0) to remove Ana. Append Claire and Dave; successive pop(0) operations remove Bob, Claire, and Dave in that order. The first arrival is therefore the first departure. section 26.4
Listing 26.5. A queue of people represented by a list
line = [] #1
line.append('Ana') #2
line.append('Bob') #3
line.pop(0) #4
line.append('Claire') #5
line.append('Dave') #5
line.pop(0) #6
line.pop(0) #6
line.pop(0) #6
Follow the queue operations line by line: append adds people to the end, while pop(0) removes the person at the front. section 26.4
To turn the idea into a reusable queue object, decide:
- Which data structure represents the queue. section 32.3
- Which methods add one or many items, remove one or many items, report size, and display the queue. section 32.3
- How objects are created and used through a sequence of operations. section 32.3






















