Back to Developer Roadmap

Stacks

src/data/roadmaps/datastructures-and-algorithms/content/[email protected]

4.01.0 KB
Original Source

Stacks

A stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO (Last In First Out) or FILO (First In Last Out). Mainly three basic operations are performed in the stack:

  1. Push: adds an element to the collection.

  2. Pop: removes an element from the collection. A pop can result in stack underflow if the stack is empty.

  3. Peek or Top: returns the top item without removing it from the stack.

The basic principle of stack operation is that in a stack, the element that is added last is the first one to come off, thus the name "Last in First Out".

Visit the following resources to learn more: