Question 01

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Question 01:

Write a C++ program to implement two stacks in one linked list where the first stack starts from
the 0th position and the second stack starts from the last position of the list. Implement
functions push1, push2, pop1, and pop2 to manipulate the two stacks.

Question 02:
Modify the above program to store even integers in one stack and odd integers in the other.
Implement functions to push and pop elements from each stack accordingly.

Question 03:
Implement a C++ program to find the next greater element for each element in an stack.

Question 04:
Implement constant sized stack and if we enter more than that size it should replace with the
smallest number of the stack.

Question 05:
Write a C++ program to add two polynomials represented as linked lists. Each node of the
linked list represents a term in the polynomial (coefficients and exponents). Implement addition
of polynomials using stack-based operations.

Question 06:
Implement undo and redo functionalities for a text editor using a linked list-based stack in C++.
Design a program that maintains a stack of document states, allowing users to undo and redo
changes to the document.

Question 07:
Implement a C++ program to sort an linked list of integers using two linked list-based stacks.
Write a program that uses two stacks to implement a sorting algorithm and sorts the array in
ascending order.
Question 08:
implement a C++ program to check if a given string is a palindrome using a linked list-based
stack. Write a program that determines whether a string is a palindrome by comparing
characters using the stack.

Question 09:
Implement a function to create and copy of a stack in C++. Write a program to demonstrate the
copying of a stack in linked list.

Question 10:
Write a C++ program to check if a given string of brackets (e.g., {}, (), []) is properly matched
using a stack. Implement a function that returns true if the brackets are balanced and false
otherwise.

Question 11:
Write a C++ program to remove duplicate elements from a stack. Implement a function that
takes a stack as input and removes any duplicate elements, keeping only the first occurrence of
each element.

Question 12:
Write a C++ program to find the intersection of two stacks. Implement a function that takes two
stacks as input and returns a new stack containing elements common to both input stacks,
preserving their order.

Question 13:
Write a C++ program to check if one stack is a subset of another stack. Implement a function
that takes two stacks as input and returns true if all elements of the first stack are present in the
second stack (in any order), and false otherwise.

Question 14:
Write a C++ program to concatenate two stacks into a single stack. Implement a function that
takes two stacks as input and returns a new stack containing elements from both input stacks,
preserving their order.
Question 15:
Write a C++ program to swap the top two elements of a stack. Implement a function that takes
a stack of integers as input and swaps the positions of the top two elements in the stack.

You might also like