UCS301 Data Structures
Lab Assignment 3: Stacks
(Week 3)
1. Develop a menu driven program demonstrating the following operations on a Stack using array:
(i) push(), (ii) pop(), (iii) isEmpty(), (iv) isFull(), (v) display(), and (vi) peek().
2. Given a string, reverse it using STACK. For example “DataStructure” should be output as
“erutcurtSataD.”
3. Write a program that checks if an expression has balanced parentheses.
4. Write a program to convert an Infix expression into a Postfix expression.
5. Write a program for the evaluation of a Postfix expression.
Additional Questions
1. Given an array A, find the nearest smaller element for every element A[i] in the array such that the
element has an index smaller than i.
[Link]
2. Design a stack that supports getMin() in O(1) time and O(1) extra space.
[Link] space/
3. Given an array arr[ ] of integers, the task is to find the Next Greater Element for each element of the
array in order of their appearance in the array. Note: The Next Greater Element for an element x is
the first greater element on the right side of x in the array. Elements for which no greater element
exist, consider the next greater element as -1.
Next Greater Element (NGE) for every element in given Array - GeeksforGeeks
4. Given an array of integers temperatures represents the daily temperatures, return an
array answer such that answer[i] is the number of days you have to wait after the ith day to get a
warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead.
Daily Temperatures - LeetCode
5. You have an array A of integers of size N, an array B (initially empty) and a stack S (initially
empty). You are allowed to do the following operations:
a) Take the first element of array A and push it into S and remove it from A.
b) Take the top element from stack S, append it to the end of array B and remove it from S.
You have to tell if it possible to move all the elements of array A to array B using the above
operations such that finally the array B is sorted in ascending order.
Stack Sort Practice Problem in Amazon Coding Interview Questions