Stack and Queue C/C++ Programs
The stack and queue are popular linear data structures with a wide variety of applications. The stack follows LIFO (Last In First Out) principle where the data is inserted and extracted from the same side. On the other hand, the queue follows FIFO (First In First Out) principle, i.e., data is inserted at one side and extracted from the other side.
In this article, we will study some of the most common practice problems in C/C++ to improve our understanding of stack and queue data structures.
Prerequisite: Stack Data Structure, Queue Data Structure
Stack Practice Problems in C/C++
The following is the list of C/C++ programs based on the level of difficulty:
Easy
- How to Reverse a String Using Stack
- Implement Two Stacks in an Array
- Check for Balanced Brackets in an Expression (Well-formedness)
- Remove all Duplicate Adjacent Characters from a String Using Stack
- Evaluation of Postfix Expression
- Check if Two Strings after Processing Backspace Character are Equal or Not
- Expression Contains Redundant Bracket or Not
- Find Maximum Depth of Nested Parenthesis in a String
- Find the Nearest Smaller Numbers on Left Side in an Array
- Sort a Stack Using a Temporary Stack
Medium
- How to Reverse a Stack Using Recursion
- Convert Infix Expression to Postfix Expression
- Next Greater Element (NGE) for Every Element in Given Array
- The Stock Span Problem
- Design a Stack with Operations on Middle Element
- Simplify the Directory Path (Unix Like)
- Minimum Number of Parentheses to be Added to Make it Valid
- Design and Implement Special Stack Data Structure | Added Space Optimized Version
- Next Greater Frequency Element
- Trapping Rain Water
Hard
- Length of the Longest Valid Substring
- Form Minimum Number from Given Sequence
- Largest Rectangular Area in a Histogram Using Stack
- Maximum Size Rectangle Binary Sub-matrix with All 1s
- Sum of Minimum Elements of All Subarrays
- Check if a Triplet of Buildings can be Selected such that the Third Building is Taller Than the First Building and Smaller than the Second Building
- Range Queries for Longest Correct Bracket Subsequence Set | 2
- Design a Stack which can Give Maximum Frequency Element
- Find Maximum of Minimum for Every Window Size in a Given Array
- Design Custom Browser History Based on Given Operations
Queue Practice Problems in C/C++
The following is the list of C/C++ programs based on the level of difficulty:
Easy
- Reversing a Queue
- Reversing the First K Elements of a Queue
- Implement Queue using Two Stacks
- Implement Stack using Queue
- Minimum Sum of Two Numbers Formed from Digits of an Array
- Maximum Number of Diamonds that can be gained in K Minutes
- First Negative Integer in Every Window of Size K
- First Negative Integer in Every Window of Size K
- Connect N Ropes with Minimum Cost
Medium
- Sorting a Queue without Extra Space
- Find the First Circular Tour that Visits All Petrol Pumps
- Design a Hit Counter
- Flood Fill Algorithm
- An Interesting Method to Generate Binary Numbers from 1 to N
- Minimum Sum of Squares of Character Counts in a Given String after Removing K Characters
- Interleave the First Half of the Queue with the Second Half
- Minimum Time Required to Rot All Oranges
- Sliding Window Maximum (Maximum of All Subarrays of Size K)
Hard
- Find the First Non-repeating Character from a Stream of Characters
- Sum of Minimum and Maximum Elements of all Subarrays of Size K
- An Interesting Method to Generate Binary Numbers from 1 to n
- Snake and Ladder Problem
- Find the First Circular Tour that Visits all Petrol Pumps
- Shortest Path in a Binary Maze
Contact Us