当前位置:网站首页>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)
- 剑指 Offer 05. 替换空格
- Google sitemap files for rails Projects - Google sitemap files for rails projects
- Speech recognition learning summary
- Guess riddles (10)
- How can fresh students write resumes to attract HR and interviewers
- How apaas is applied in different organizational structures
- Search data in geo database
- MATLAB小技巧(28)模糊綜合評價
- C language data type replacement
猜你喜欢
随机推荐
The first week of summer vacation
Buildroot system for making raspberry pie cm3
Example 009: pause output for one second
Shell script realizes the reading of serial port and the parsing of message
实例006:斐波那契数列
Example 008: 99 multiplication table
Arduino+a4988 control stepper motor
Arduino operation stm32
How to manage the performance of R & D team?
Classification of plastic surgery: short in long long long
Example 006: Fibonacci series
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?
第十八章 使用工作队列管理器(一)
Digital analog 1: linear programming
Chapter 18 using work queue manager (1)
Illustration of eight classic pointer written test questions
Affected tree (tree DP)
go依赖注入--google开源库wire
MATLAB小技巧(28)模糊綜合評價
99 multiplication table (C language)