// Postfix evaluation.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include "stackNew.h"
#include <string>
#include "stdlib.h"
#include <cctype>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char Exp;
string postfix;
stackNew Operands;
float item1, item2, result;
cout<<"please enter the exp<B></B>ression you want to evaluate: "<<endl;
cin>>postfix;
int i= 0;
Exp= postfix[i];
while (i < postfix.length())
{
if (isdigit(Exp))
{
int x;
x= atoi(Exp);
Operands.Push(x);
}
else
{
item2 = Operands.Pop();
item1 = Operands.Pop();
switch (Exp)
{
case '+': result= item1+item2;
break;
case '-': result= item1-item2;
break;
case '*': result= item1*item2;
break;
case '/': result= item1/item2;
break;
}
Operands.Push (result);
}
i++;
Exp= postfix[i];
}
if (!Operands.isEmpty ())
{
result= Operands.Pop();
}
cout<<"The postfix exp<B></B>ression "<<postfix<<" after evaluation is: "<<result<<endl;
return 0;
}