Professional Documents
Culture Documents
Exercise 1
Write a program that implements the stack with Max_size=7.Program must have following functions
PUSH()
POP()
Display()
Output:
Exercise 2
There are five balls of different colours (Red, Green, Blue, Orange, and Yellow) in a jar. Players take the
ball from jar for playing. Write a program that maintains the stack of balls and prints the following
Exercise 3
#include <iostream>
#include <string>
using namespace std;
int main() {
string exp;
cout << "Enter a postfix expression: ";
cin >> exp;
int result = evaluatePostfix(exp);
cout << "Result: " << result << endl;
system("Pause");
}
#include <iostream>
using namespace std;
void Push(string colors[], int& top, string item) {
if (top != 4) {
top = top + 1;
colors[top] = item;
}
else {
cout << " NO Ball Available! Player6 occured. " << endl;
}
}
void Pop(string colors[], int & top, int & player) {
if (top == -1) {
cout << " Stack Underflow!" << endl;
}
else {
cout << " Player " << player << " Took " << colors[top] << " Color Ball"
<< endl;
player++;
top = top - 1;
}
}
void display(string colors[], int & top) {
for (int i = top; i >= 0; i--) {
cout << colors[i] << endl;
}
}
void main() {
string colors[5];
int player = 1;
int top = -1;
string item;
Push(colors, top, "RED");
Push(colors, top, "GREEN");
Push(colors, top, "BLUE");
Push(colors, top, "ORANGE");
Push(colors, top, "YELLOW");
Push(colors, top, "YELLOW");
display(colors, top);
Pop(colors, top, player);
Pop(colors, top, player);
Pop(colors, top, player);
Pop(colors, top, player);
Pop(colors, top, player);