#include <iostream>
#include <string.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <algorithm>
#include <math.h>
using namespace std;
double exp()
{
char str[100];
cin >> str;
switch (str[0])
{
case '+':
return exp()+exp();
case '-':
return exp()-exp();
case '*':
return exp()*exp();
case '/':
return exp()/exp();
default:
return atof(str);
break;
}
}
int main()
{
printf("%f\n",exp());
return 0;
}
逆波兰表达式的递归定义:
1.一个数(递归出口)
2.运算符 逆波兰表达式 逆波兰表达式
以样例来分析下递归的流程