Stacks, text files and writing modules
Watch the whole lecture free
Make a free account to watch every lecture to the end: 4 practice questions, 2 real past-paper questions with the answers explained, the mistakes that lose marks, the full-marks tip, a one-card summary and a quick quiz.
That was the teaching part. The rest of this lecture is free with an account: 4 practice questions, 2 real past-paper questions with the answers explained, the mistakes that lose marks, the full-marks tip, a one-card summary and a quick quiz.
No password needed now: we email you a link to set one. Already have an account? Sign in, then come back to this page.
The teaching part (1 min) is free to watch. A free account opens the whole lecture: 4 practice questions, 2 real past-paper questions with the answers explained, the mistakes that lose marks, the full-marks tip, a one-card summary and a quick quiz.
What this lecture covers
- Last in, first out
- The stack
- Stack operations
Read the transcript of the teaching part
Last time
Before we start: last time, in Reading and writing text files, you learned these points. Here they are again on one card. Keep them in mind, because today builds on them.
Last in, first out
A pile of plates. You add to the top and take from the top. That is a stack, and it is how a computer remembers where to return to. Data in variables vanishes when the power goes off, so programs also save to text files. Then Cambridge asks you to write modules: functions and procedures that do one job properly.
The stack
A stack is a last in, first out structure. The last item pushed on is the first one popped off. PUSH adds an item to the top. POP removes the top item. A pointer, TopOfStack, shows where the top is. A stack can be implemented using an array, with the pointer holding the index of the last item added.
Stack operations
A stack in memory locations 200 to 207 holds P, Q, R, S, with S on top at 203. TopOfStack is 203. POP removes S, POP removes R. Now the top is Q at 201. PUSH A, then PUSH B: the stack is P, Q, A, B. POP removes B. PUSH C, PUSH D: the final stack is P, Q, A, C, D, with TopOfStack at 204.
How often it comes up
How often Cambridge has asked each part, counted by ExamYard from every past paper in its question bank: Reading and writing text files · Stacks · Writing modules.
The whole chapter: Files, Data Structures and Modules.
Chapter 10: Data types and structures
- Linked lists, queues, procedures, functions and text files 6 min
- Stacks, text files and writing modules 6 min
Also for A Level Computer Science 9618
Which topics come up most in A Level Computer Science 9618 past papers, counted from every paper since 2004: Paper 1 topic frequency, Paper 2 topic frequency.