Stacks: push, pop and peek – OCR A Level Computer Science lesson (H446)
Students learn to trace push, pop and peek on an array-based stack and write a pop that checks for an empty stack and moves the top pointer before returning.
Lesson 3 of 15 in unit 12.8 Data Structures, taught in Year 12, Spring 2. It answers one big question: Why must the last parcel loaded be the first out?
By the end, students can trace push, pop and peek on an array-based stack and write a pop that checks for an empty stack and moves the top pointer before returning.
- The Build (the main task)
- Write the push and pop functions for a stack of 10 parcels in a Tillbrook van, held in an array with a top pointer that starts at -1; pop must return the parcel removed (6 marks).
- Support version
- Part-filled OCR pseudocode for both functions, with the full and empty checks and the pointer lines missing, and a trace table of the van stack to test them.
- Challenge
- Write peek, and explain why loading a van as a stack means the route must be planned before loading.
- Real-world link
- Parcels loaded into the back of a Tillbrook van: the last one in is the only one the driver can reach.
- Key words
- Stack, Top pointer and Last in, first out (LIFO), each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “pop() can return the item first and decrement the top pointer afterwards”; “The stack is full when top equals the array's length”.
- OCR H446 specification
- 1.4.2 (b); (c); 2.3.1 (e) (algorithms for the main data structures: stacks, queues, trees and linked lists, with depth-first (post-order) and breadth-first traversal of trees).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Students can do it all on paper.
Also sold in the Data Structures unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
An independent resource written for OCR A Level Computer Science (H446). It is not endorsed by OCR or Cambridge University Press & Assessment. Programming project (NEA) lessons teach general skills on a made-up example project and give supervised time, within JCQ's rules on the help a centre may give.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for A Level Computer Science
See allStudents learn to choose a record, tuple, list or array of up to three dimensions for given data, and declare each.
Free sample lessonStudents learn to compare static and dynamic data structures and justify one for a given use.
Students learn to trace enqueue and dequeue on linear and circular queues, using front and rear pointers and MOD to wrap round.
Written for the specifications named. Not endorsed by or affiliated with any exam board.