Define a stack | An abstract data type that holds an ordered, linear sequence of items where items are added and removed from the front |
What are the two main operations of a stack? | Push
Pop |
What does the push() operation do for a stack? | an item is added to the top of the stack |
What does the pop() operation do for a stack? | the top item is removed from the stack
|
For a stack what is a pointer? | A variable that marks the top of the stack |
Give some computational functions of stacks | Compilers can use a stack to check the syntax of programs
For Reverse Polish Notation
Use of a stack for function calls |
Describe what reverse polish notation is | Writen notation where the operator comes after the values it operates on |
Whats another name for Reverse Polish Notation? | postfix |
State the advantages of postfix notation | No need for brackets
No need to define operator precedence (BIDMAS)
Expression can be evaluated serially – no need to backtrack
So, faster for computer to evaluate |
How is a stack used for nested function calls? | Data is placed on a “stack frame” which ensures that the data retrieved is the most recently stored, ensuring that the function calls in the correct order |