Stacks Flashcards
What is a stack?
an abstract data type which uses a concept of first in last out
What is it often used for ?
To undo actions in browsers and word editors
What types of stacks can there be?
Static and dynamic
What is necessary to get a stack to work?
pointer to the top of a stack and variable related to the size (amount of elements stored)
What does the push() do ?
Adds an item
What does a pop() do?
removes and returns the first item
peek()?
returns the top item but doesn’t remove it
isEmpty?
tests to see whether the stack is empty
isFull?
checks to see whether stack is full
What is the value of the pointer if a stack is empty?
-1
How can a stack cause overflow and underflow errors?
for example trying to pop() on an empty stack
What is a call stack?
A stack used to store information about active programs/subroutines (must be running)
What does a call stack store?
return addresses of subroutines (if nested then several return addresses are stored)
parameters
local variables
Why can memory run out with recursion?
As many addresses will need to be stored, consequently running out of memory
What is a call stack composed of?
A stack frame, this frame contains related information about a subroutine that is active