13 terms

FUNDAMENTALS OF DATA STRUCTURES - STACKS- AQA COMPUTER SCIENCE A LEVEL

STUDY
PLAY

Terms in this set (...)

What is a stack?
abstract data type where the last item added to the stack is the first to leave (LIFO)
Where are stacks used?
in calculations,
holding return addresses when subroutines are called,
back button on web browser,
undo button on word processr
How are they implemented
dynamic (list)

static (array with two pointers)
test if stack is empty
stack.isEmpty()

return True/False
test if stack is full
stack.isFull()

return True/False
return top item from stack but not remove
stack.peek()

return top item
remove and return top item
stack.pop()

return top item
add new item to top of stack
stack.push(item)
what is stack overflow?
when an item is attempted to be pushed onto a stack but the stack is full
what is stack underflow?
when the stack is empty and an item is being attempted to be popped
pseudocode to push onto stack
SUB pushToStack
IF topOfStack = maxSize THEN
OUTPUT "Stack is full - no space available"
ELSE
INPUT newStackItem
topOfStack = topOfStack + 1
stack(topOfStack) = newStackItem
ENDIF
ENDSUB
pseudocode to pop from stack
SUB popFromStack
IF (topOfStack = 0) THEN
OUTPUT "Stack is empty - no data to pop"
ELSE
OUTPUT stack[topOfStack]
topOfStack = topOfStack - 1
ENDIF
ENDSUB
What is a stack frame?
stores information about active subroutines while computer programs are running

holds return addresses