30.2. Stacks and Queues¶
30.2.1. Container Class Design Issues¶
- Storing a record vs. Storing a reference to a record
- Homogeneity: Allow different record types? Check and block?
- Deletion: What happens to the record?
30.2.2. Stacks¶
LIFO: Last In, First Out.
Restricted form of list: Insert and remove only at front of list.
Notation:
- Insert: PUSH
- Remove: POP
- The accessible element is called TOP.
30.2.3. Stack ADT¶
30.2.4. Array-Based Stack (1)¶
Issues:
- Which end is the top?
- Where does “top” point to?
- What are the costs of the operations?
30.2.5. Array-Based Stack (2)¶
30.2.6. Linked Stack¶
What are the costs of the operations?
How do space requirements compare to the array-based stack implementation?
30.2.7. Queues¶
FIFO: First in, First Out
Restricted form of list: Insert at one end, remove from the other.
Notation:
- Insert: Enqueue
- Delete: Dequeue
- First element: Front
- Last element: Rear
30.2.8. Queue Implementation (1)¶
30.2.9. Queue Implementation (2)¶
1 / 9 Settings<<<>>>A more efficient implementation can be obtained by relaxing the requirement that all elements of the queue must be in the first n positions of the array. We still require that the queue be stored be in contiguous array positions, but the contents of the queue will be permitted to drift within the array.