当前位置:网站首页>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_map
Defines the priority of the operator , The priority of a given operator can be obtained .
unordered_map<char</
边栏推荐
- Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
- 实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
- How apaas is applied in different organizational structures
- Agile project management of project management
- Array integration initialization (C language)
- Example 010: time to show
- Business modeling | process of software model
- Example 007: copy data from one list to another list.
- 第十八章 使用工作队列管理器(一)
- Bluebridge cup internet of things competition basic graphic tutorial - clock selection
猜你喜欢
Daily question - input a date and output the day of the year
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Guess riddles (6)
Example 007: copy data from one list to another list.
实例009:暂停一秒输出
Shell script
实例006:斐波那契数列
Guess riddles (2)
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
随机推荐
2022.7.4-----leetcode. one thousand and two hundred
Mathematical modeling: factor analysis
STM32 summary (HAL Library) - DHT11 temperature sensor (intelligent safety assisted driving system)
Illustration of eight classic pointer written test questions
Sword finger offer 09 Implementing queues with two stacks
猜谜语啦(2)
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
Esp8266 interrupt configuration
Five design details of linear regulator
Stm32--- systick timer
STM32 --- serial port communication
Google sitemap files for rails Projects - Google sitemap files for rails projects
猜谜语啦(3)
Example 010: time to show
EA introduction notes
STM32 outputs 1PPS with adjustable phase
STM32 single chip microcomputer - external interrupt
实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
TypeScript手把手教程,简单易懂
轮子1:QCustomPlot初始化模板