Skip to content
This repository was archived by the owner on Oct 16, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Postfix_Notation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include<bits/stdc++.h>
using namespace std;

int postfixEvaulation(string s)
{
stack<int> st;
for (int i = 0; i < s.length(); i++)
{
if (s[i]>='0' && s[i]<='9')
st.push(s[i]-'0'); //-0 islye kiya for intiger value

else
{
int op2=st.top();
st.pop();
int op1=st.top();
st.pop();

switch (s[i])
{

case '+':
st.push(op1+op2);
break;

case '-':
st.push(op1-op2);
break;

case '*':1
st.push(op1*op2);
break;

case '/':
st.push(op1/op2);
break;

case '^':
st.push(pow(op1,op2));
break;
}
}

}
return st.top();
}

int main()
{
cout<<postfixEvaulation("46+2/5*7+")<<endl;
return 0;
}