当前位置:网站首页>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</
边栏推荐
- MySQL之MHA高可用集群
- Sword finger offer 05 Replace spaces
- MATLAB小技巧(28)模糊綜合評價
- 猜谜语啦(3)
- STM32 --- configuration of external interrupt
- U8g2 drawing
- 【日常训练--腾讯精选50】557. 反转字符串中的单词 III
- Guess riddles (6)
- Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
- leetcode - 445. Add two numbers II
猜你喜欢
随机推荐
Affected tree (tree DP)
STM32 --- GPIO configuration & GPIO related library functions
An enterprise information integration system
Business modeling of software model | stakeholders
Weidongshan Internet of things learning lesson 1
Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?
MySQL之MHA高可用集群
Buildroot system for making raspberry pie cm3
How to write cover letter?
The first week of summer vacation
MATLAB skills (28) Fuzzy Comprehensive Evaluation
关于线性稳压器的五个设计细节
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
【三层架构】
Run menu analysis
Example 009: pause output for one second
Stm32--- systick timer
696. 计数二进制子串
Example 008: 99 multiplication table