Professional Documents
Culture Documents
#include <iostream>
#include <stack>
stack<int> stack;
stack.push(exp[i] - '0');
else
int x = stack.top();
stack.pop();
// if (stack.empty())
int y = stack.top();
stack.pop();
if(exp[i] == '+')
stack.push(y + x);
stack.push(y - x);
stack.push(y * x);
stack.push(y / x);
return stack.top();
int main()
string exp;
cin>>exp;
return 0;
#include<iostream>
#include<stack>
{ stack <char> s;
char output[50],t;
for(int i=0;a[i]!='\0';i++)
{ char ch = a[i];
switch(ch)
case '^':
case '-':
case '+':
case '/':
break;
s.pop();
cout<<t;
break;
if (isalpha(ch))
cout<<ch;
int main()
char a[15];
for(int i=0;i<15;i++)
{
cin>>a[i];
Postfix(a);
return 0;
#include <iostream>
#include<stack>
// an operator or not.
bool isOperator(char c)
// operator.
int getPriority(char C)
if (C == '-' || C == '+')
return 1;
return 2;
else if (C == '^')
return 3;
return 0;
stack<char> operators;
stack<string> operands;
// If current character is an
if (infix[i] == '(') {
operators.push(infix[i]);
// If current character is a
// not found.
operators.top() != '(') {
// operand 1
operands.pop();
// operand 2
operands.pop();
// operator
char op = operators.top();
operators.pop();
// in form operator +
// operand1 + operand2.
operands.push(tmp);
// stack.
operators.pop();
// If current character is an
else if (!isOperator(infix[i])) {
operands.push(string(1, infix[i]));
// If current character is an
else {
getPriority(infix[i]) <=
getPriority(operators.top())) {
operands.pop();
operands.pop();
char op = operators.top();
operators.pop();
operands.push(tmp);
}
operators.push(infix[i]);
// operands stack.
while (!operators.empty()) {
operands.pop();
operands.pop();
char op = operators.top();
operators.pop();
operands.push(tmp);
return operands.top();
// Driver code
int main()
{
string s = "(A-B/C)*(A/K-L)";
return 0;
}}
#include <bits/stdc++.h>
bool isOperand(char x)
// expression
stack<string> s;
{
if (isOperand(exp[i]))
{
s.push(op);
}
// an operator.
else
{
s.pop();
s.pop();
op1 + ")");
}
}
// infix.
return s.top();
// Driver code
int main()
return 0;