Tutorial 3
📚
Stack
9618 A-Level
i
Note: for AS, the syllabus states you won't be asked to write a stack from scratch - but they do have "fill in the blank" type questions where they give you most of the code and ask you to complete it
For A2, you can be asked to write an entire stack from scratch, including the push and pop modules
It may be useful to search (CTRL + F) for "stack" questions in the (combined) past papers
If you find any bugs/edge cases in this code, please contact me
1
Stack
A stack is a LIFO (last-in, first-out) data structure - there are two operations and we will require an additional pointer variable that points to the top element in the stack
- Push: if the stack isn't full, a new item will be added to the top of the stack and the top pointer will be incremented
- Pop: if the stack isn't empty, the top item will be removed and returned from the stack and the top pointer will be decremented
More detailed comments can be seen in the code
Extension details/answers will be added: reverse a string, check balanced brackets, evaluate postfix expression