#include<iostream>
#include<math.h>
using namespace std;
const int Max=5;
class stack
{
private:
int a[Max];
int top;
public:
stack()
{
top=-1;
}
int full(void)
{
if(top==Max-1)
{
cout<<"stack is full";
return(1);
}
else
return(0);
}
int empty(void)
{
if(top==-1)
return(1);
else
return(0);
}
int peek(void)
{
return(a[top]);
}
void push(int x)
{
top++;
a[top]=x;
}
int pop(void)
{
int x=a[top];
top--;
return(x);
}
void display(void)
{
for(int i=top;i>=0;i--)
{
cout<<endl<<a[i];
}
}
};
int evaluate(char x,int op1,int op2)
{
if(x=='+') return(op1+op2);
if(x=='-') return(op1-op2);
if(x=='*') return(op1*op2);
if(x=='/') return(op1/op2);
if(x=='%') return(op1%op2);
if(x=='$') return(pow(op1,op2));
}
int main()
{
stack s;
char x;
int op1,op2,val;
cout<<"\n Enter Postfix Expression:";
while((x=getchar())!='\n')
{
if(isdigit(x))
[Link](x-48);
else
{
op2=[Link]();
op1=[Link]();
val=evaluate(x,op1,op2);
[Link](val);
}
}
val=[Link]();
cout<<"\n Answer="<<val;
return(0);
}
/*
OUTPUT:-
PS D:\Chaitanya programs> cd "d:\Chaitanya programs\" ; if ($?) { g++
arrray_evaluation.cpp -o arrray_evaluation } ; if ($?) { .\arrray_evaluation }
Enter Postfix Expression:623+-382/+*2$3+
Answer=52
PS D:\Chaitanya programs>
*/