Professional Documents
Culture Documents
Name
Muhammad Hamza
Roll No
F22NSEEN1M01006
Submitted to
Dr. Hina Afreen
#include <iostream>
#include <stack>
using namespace std;
class MyStack {
private:
stack<int> data;
public:
// Function to push an item onto the stack
void pushItem(int value) {
data.push(value);
cout << "Pushed: " << value << endl;
}
return 0;
}
Output:
Pushed: 7
Pushed: 16
Pushed: 27
Pushed: 37
Pushed: 47
Peeked: 47
Popped: 47
Popped: 37
Popped: 27
Popped: 16
Popped: 7
Stack is empty. Cannot peek.
2. Write a program that convert infix expression to postfix expression.
#include <iostream>
#include <stack>
while (!operators.empty()) {
postfixExpression += operators.top();
operators.pop();
}
return postfixExpression;
}
int main() {
string infixExpression;
return 0;
}
Output: