CCVB
CCVB
BY:
Q1:
#include <iostream>
#include <stack>
template<typename T>
while (!st.empty()) {
st.pop();
int main() {
printStack(myStack);
return 0;
Q2:
#include <iostream>
#include <stack>
T findMaxInStack(stack<T> st) {
if (st.empty()) {
return T();
T maxVal = st.top();
st.pop();
while (!st.empty()) {
maxVal = st.top();
st.pop();
return maxVal;
int main() {
cout << "Maximum element in the stack: " << maxElement << endl;
return 0;
Q3:
Write a c++ program to print the word “ Welcome in FET” in revere order?
#include <iostream>
#include <iostream>
#include <stack>
#include <string>
stack<char> charStack;
charStack.push(ch);
while (!charStack.empty()) {
charStack.pop();
return 0;
Q4:
Write a program in C++ to separate integers stored in a stack into two stacks one for the even integers
and the other for odd ones.
#include <iostream>
#include <stack>
int main() {
stack<int> mainStack;
stack<int> evenStack;
stack<int> oddStack;
mainStack.push(10);
mainStack.push(5);
mainStack.push(8);
mainStack.push(15);
mainStack.push(12);
while (!mainStack.empty()) {
if (mainStack.top() % 2 == 0) {
evenStack.push(mainStack.top());
} else {
oddStack.push(mainStack.top());
mainStack.pop();
while (!evenStack.empty()) {
evenStack.pop();
while (!oddStack.empty()) {
oddStack.pop();
return 0;