Stack Data Structure: Practical Applications & Operations

You wouldn’t be able to read this now if stacks didn’t exist. Stacks described from a practical perspective for engineers.

Adarsh Menon
Oct 5, 2020 · 4 min read

Stack is one of the most popular and widely known data structures in computer science, and one of the easiest to learn and understand. But often, maybe because of the way it is introduced or taught, it seems kind of useless and boring to learn.

Stacks are not one of those useless things that you need to learn just to pass your exams or to crack the coding interview, but they are actually used for a lot of things that you do daily on the computer.

Watch the video version if you prefer that :)

Practical Applications

  • They are the building blocks of function calls and recursive functions. Yes, this is a common application that you maybe aware of, but think about it — right now there are hundreds (if not thousands) of functions existing on your call stack in memory maintained by your OS. Every time a function is called, some memory is reserved (PUSH) for it on the call stack, and when it returns, the memory is deallocated (POP).

The Stack Pattern

So what makes stacks special ? Well, it is the Last In First Out property — the element that was added last to the stack is removed first. There is only one way to insert or remove an element from a stack — from the top.

Stacks are often compared to a stack of plates in restaurant kitchens, where adding a new plate or removing an existing one from the stack is only possible from the top.

In computer science, instead of plates we store objects in the stack. They could be anything from numbers, strings, memory addresses, entire functions or even other data structures.

There are three operations that can be performed on a stack data structure:

  • PUSH: adds an element to the stack

Now say you push 3 items into the stack, A, B and C in order. Now C is on the top. Popping off elements would give you C, B and A. So the LIFO pattern can be also used to reverse a set of ordered items.

Implementing Stacks

Most programming languages nowadays have an inbuilt library for implementing stacks. If you are interested, you can implement it yourself from scratch too. Here are common implementations of stacks in Python and C++, especially useful if you are preparing for coding interviews.


In python, the list data structure can be used as a stack.


The C++ STL (Standard Template Library) has a great implementation of stack.

The idea behind this whole post was simply to appreciate how the simple stack data structure plays a very important role in how we use computers every day. If you enjoyed this, I am planning to do a series on other data structures as well, so please consider following and check out my YouTube Channel.

For questions, comments, feedback feel free to email me at or connect with me on Twitter (@adarsh_menon_).

The Startup

Get smarter at building your thing. Join The Startup’s +724K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store