📄 postfixcompute1.cpp
字号:
// PostFixCompute.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "InfixToPostfix.h"
#include<iostream>
#include<string>
#include<stack>
#include<cctype>
#include<vector>
#include<string>
using namespace std;
int postFixCompute(char *exp)
{
stack<int> *opnd=new(stack<int>);//操作数栈
char ch=*exp;
int x=0,y,z,flag=FALSE;
int result;
while(ch!='#')
{
if(!Operator(ch)) //如果当前字符不是运算符
{
if(ch!=' ')
{
x=x*10+(int)(ch)-48; //计算操作数
flag=TRUE;
}
else
{
if(flag)opnd->push(x); //操作数入栈
x=0;
flag=FALSE;
}
}
else //当前字符为运算符,两个操作数出栈,计算并将结果入栈
{
x=opnd->pop();
y=opnd->pop();
z=calc(y,ch,x);
opnd->push(z);
}
ch=*(++exp); //取下一字符
}
result=opnd->pop();
return(result);
}
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -