Stack

A stack is an ordered collection of objects

Ex: Deleting words/letters with ´backspace´, “Undo” feature in editors, browser back/forward navigation.

Stack ADT methods

push() - add to the stack (no output)

pop() - remove TOP ITEM form the stack (output - removed item)

peek() - see the top item (output is the top item)

isEmpty() - check if is empty (output - true / false)

size() - length of the stack (output - int)

PS: pop() and peek() will throw an exception if the stack is empty

PS2: header of the linked list points to the 1st - that’s important to be localized in memory

Linked list to implement a stack

image.png