Stack Data Structure
Last Updated :
27 Mar, 2025
Improve
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). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first, comes out last.
It behaves like a stack of plates, where the last plate added is the first one to be removed. Think of it this way:
- Pushing an element onto the stack is like adding a new plate on top.
- Popping an element removes the top plate from the stack.
Basics of Stack Data Structure
- Introduction to Stack
- Stack Array Implementation
- Stack Linked List Implementation
- Stack Implementation using Deque
- Applications of Stack
Implementations of Stack in Different Languages
Easy Problems on Stack Data Structures
- The Celebrity Problem
- Implement Queue using Stacks
- Implement two stacks in an array
- Implement Stack using Queues
- Stack using priority queue or heap
- Stack using single queue
- Infix to Postfix
- Prefix to Infix
- Prefix to Postfix
- Postfix to Prefix
- Postfix to Infix
- Infix To Prefix
- Check for balanced parentheses
- Arithmetic Expression Evalution
- Evaluation of Postfix Expression
- Reverse a stack using recursion
- Reverse Words
- Reverse a string using stack
- Reversing a Queue
- Reversing the first K of a Queue
- A Data Structure with O(1) Operations
Medium Problems on Stack Data Structures
- k Stacks in an Array
- Mergable Stack
- Previous Smaller Element
- Next Greater Element
- Stock Span Problem
- Buildings Facing Sun
- Next Smaller of next Greater in an array
- Next Greater Frequency Element
- Max product of indexes of greater on left and right
- Iterative Tower of Hanoi
- Sort a stack using a temporary stack
- Reverse a stack without using extra space in O(n)
- Delete middle of a stack
- Check if a queue can be sorted into another queue
- Check if an array is stack sortable
- Iterative Postorder Traversal | Set 1 (Using Two Stacks)
- Index of closing bracket for a given opening bracket
- Max Diff between nearest left and right smaller elements
- Delete consecutive same words in a sequence
Hard Problems on Stack Data Structures
- Largest Rectangular Area in a Histogram
- Sum of Max of all Subarrays
- Max of Mins of every window size
- Design a stack that supports getMin()
- Design a stack with max frequency operations
- Print next greater number of Q queries
- Length of the longest valid substring
- Iterative Postorder Traversal | Set 2 (Using One Stack)
- Print ancestors of a given binary tree node without recursion
- Expression contains redundant bracket or not
- Find if an expression has duplicate parenthesis
- Iterative method to find ancestors in a binary tree
- Stack Permutations
- Remove brackets from an algebraic string containing + and – operators
- Range Queries for Longest Correct Bracket Subsequence
Quick Links :
Recommended: