当前位置:网站首页>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</
边栏推荐
- Pytorch entry record
- Typical low code apaas manufacturer cases
- 猜谜语啦(142)
- Google sitemap files for rails Projects - Google sitemap files for rails projects
- 实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
- Guess riddles (6)
- Stm32--- systick timer
- Chapter 18 using work queue manager (1)
- QEMU STM32 vscode debugging environment configuration
- Business modeling of software model | overview
猜你喜欢
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
猜谜语啦(4)
Business modeling of software model | vision
每日一题——替换空格
99 multiplication table (C language)
MySQL之MHA高可用集群
Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
实例007:copy 将一个列表的数据复制到另一个列表中。
TypeScript手把手教程,简单易懂
实例004:这天第几天 输入某年某月某日,判断这一天是这一年的第几天?
随机推荐
Business modeling of software model | overview
GEO数据库中搜索数据
Lori remote control LEGO motor
leetcode - 445. 两数相加 II
剑指 Offer 09. 用两个栈实现队列
2022.7.4-----leetcode.1200
Guess riddles (142)
图解八道经典指针笔试题
【日常训练--腾讯精选50】557. 反转字符串中的单词 III
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
每日一题——替换空格
Classification of plastic surgery: short in long long long
Five design details of linear regulator
MHA High available Cluster for MySQL
Reasons for the insecurity of C language standard function scanf
猜谜语啦(3)
STM32---ADC
[noi simulation] juice tree (tree DP)
Affected tree (tree DP)
Void* C is a carrier for realizing polymorphism