Stacks Flashcards
What is a stack
Abstract data type , last in first out
Size()
Return top+ 1
IsEmpty()
FUNCTION is_empty(top)
IF top == -1 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION
Peek()
FUNCTION peek(stack, top)
IF is_empty(top) == True THEN
PRINT(“Stack is empty - nothing to peek”)
peeked_item = Null
ELSE
peeked_item = stack[top]
ENDIF
RETURN peeked_item
ENDFUNCTION
Push(x)
FUNCTION push(stack, top, data)
IF is_full(top) == True THEN
PRINT(“Stack is full”)
ELSE
top = top + 1
stack[top] = data
ENDIF
RETURN top
ENDFUNCTION
Pop ()
FUNCTION pop(stack, top)
IF is_empty(top) == True THEN
PRINT (“Stack is empty - nothing to pop”)
popped_item = Null
ELSE
popped_item = stack[top]
top = top - 1
ENDIF
RETURN (popped_item, top)
ENDFUNCTION
isfull()
FUNCTION is_full(top)
IF top == MAX_SIZE - 1 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDFUNCTION