AQA A-Level Computer Science · Section 4.2 Fundamentals of Data Structures
| Operation | Description | Complexity |
|---|---|---|
| Push(item) | Add item to the top of the stack | O(1) |
| Pop() | Remove and return top item | O(1) |
| Peek() | Return top item without removing | O(1) |
| isEmpty() | Returns True if stack has no items | O(1) |
| isFull() | Returns True if stack is at capacity | O(1) |
| Operation | Stack (bottom→top) | SP | Return |
|---|---|---|---|
| Push(5) | [5] | 0 | — |
| Push(3) | [5, 3] | 1 | — |
| Push(8) | [5, 3, 8] | 2 | — |
| Peek() | [5, 3, 8] | 2 | 8 |
| Pop() | [5, 3] | 1 | 8 |
| Pop() | [5] | 0 | 3 |