A Practical Guide to the Stack Data Structure

Our first linear data structure.

Play this article

To help me conceptualize stacks and also some of their functions, I usually think of it as a stack of books or a stack of Jenga bricks as you can see on the cover image above. A stack is a linear data structure that functions on the Last In First Out (LIFO) principle which means that the last element in a stack is the first one to be removed, just like a stack of books.

Stack Implementation in Python

Stack Implementation in Go

Uses of Stacks

  1. It is used to evaluate arithmetic operations.

  2. It is used in backtracking, a recursive algorithm used for solving optimization problems.

  3. It is used for delimiter checking.

  4. It is used to reverse a given set of data.

  5. It is used to process function calls.