Stack

Simple one ended linear data structure that’s also FILO, first in, last out.

Operations

  • Push: Add an item to the stack.

  • Pop: Remove the top item of the stack.

  • Peek: Look at the top item of the stack without removing it.

Implementation

Can be done with a fixed length array or dynamic length array, some languages also include an implementation (see Java’s Stack)

The idea should be to hold a pointer on the top of the stack, since we only perform at the top of the stack, this is good enough. One should be careful of attempting to remove items when the stack is empty and adding items when the stack is full.

Problems