A stack is a last in first out data structure (LIFO) that closely resembles a stack of plates.

Implementation

A stack can be implemented with just a singly linked list with a pointer to the head of the list.

Essential operations for a stack data structure are:

  • Push
  • Pop

Push adds an element to the top of the stack, pop will depending on the implementation either return the element and remove it or just remove it.

cstd

In the C standard library for C++, the following exist:

  • Top (peek at top element)
  • Push (insert)
  • Pop (remove top element)
  • Size
  • Swap