push and pop

The two basic stack operations: push adds an item to the top and pop removes and returns the item on top.

In more detail

In Python, list.append is push and list.pop() with no argument is pop, both O(1). list.pop(0) removes from the front instead, which costs O(n). Heaps also speak of push and pop, meaning insert and remove-smallest.

Related terms

Taught in

References