当前位置:网站首页>Infix expression evaluation
Infix expression evaluation
2022-07-05 08:38:00 【Stay--hungry】
The basic idea :
Define two stacks , Separate for storage Operands And Operator .
- Operands Direct access Operand stack
- For operators op,
- If operator stack is empty , Direct stack
- If it's left bracket
(, Direct stack - If the top of stack operator is left parenthesis
(, And op Is not), Then push directly - if op The priority of the higher than Top of stack operators , Direct stack
- if op The priority of the Below or equal to Top of stack operators , You need to calculate it before entering the stack
- If it's a right parenthesis
), Calculation is required , Until I met(, here(...)The result of the formula in is calculated , take(Kicked out - After each calculation , The situation in the stack will change , want Determine whether the calculation can continue ( That is, whether the current stack top operator still meets the conditions for calculation )
Be careful :(、) Brackets should be considered separately .
Some skills used :
- use
unordered_mapDefines the priority of the operator , The priority of a given operator can be obtained .
unordered_map<char</边栏推荐
- 696. Count binary substring
- Run menu analysis
- 实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
- Five design details of linear regulator
- STM32 --- configuration of external interrupt
- 实例009:暂停一秒输出
- 【日常训练--腾讯精选50】557. 反转字符串中的单词 III
- Wheel 1:qcustomplot initialization template
- [three tier architecture and JDBC summary]
- MATLAB小技巧(28)模糊綜合評價
猜你喜欢

Count the number of inputs (C language)

One question per day - replace spaces

EA introduction notes

实例007:copy 将一个列表的数据复制到另一个列表中。

猜谜语啦(142)

图解八道经典指针笔试题

Various types of questions judged by prime numbers within 100 (C language)

Arduino+a4988 control stepper motor

实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。

实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
随机推荐
Old Wang's esp8266 and old Wu's ws2818 light strip
第十八章 使用工作队列管理器(一)
Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase
Example 006: Fibonacci series
Esphone retrofits old fans
[noi simulation] juice tree (tree DP)
Guess riddles (3)
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
Typical low code apaas manufacturer cases
猜谜语啦(2)
Cmder of win artifact
Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
319. 灯泡开关
STM32 single chip microcomputer - bit band operation
MATLAB小技巧(28)模糊综合评价
go依赖注入--google开源库wire
Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
猜谜语啦(7)
How can fresh students write resumes to attract HR and interviewers