当前位置:网站首页>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</边栏推荐
- [three tier architecture and JDBC summary]
- How to manage the performance of R & D team?
- Buildroot system for making raspberry pie cm3
- TypeScript手把手教程,简单易懂
- MHA High available Cluster for MySQL
- MySQL之MHA高可用集群
- 猜谜语啦(11)
- Lori remote control commissioning record
- leetcode - 445. 两数相加 II
- UE pixel stream, come to a "diet pill"!
猜你喜欢

Keil use details -- magic wand

STM32 --- NVIC interrupt

猜谜语啦(9)

Count the number of inputs (C language)

Low code platform | apaas platform construction analysis

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

猜谜语啦(3)

剑指 Offer 05. 替换空格

Example 008: 99 multiplication table

Digital analog 1: linear programming
随机推荐
Sword finger offer 06 Print linked list from end to end
Guess riddles (7)
Void* C is a carrier for realizing polymorphism
Example 005: three numbers sorting input three integers x, y, Z, please output these three numbers from small to large.
Example 010: time to show
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
QEMU STM32 vscode debugging environment configuration
QEMU demo makefile analysis
Guess riddles (5)
Buildroot system for making raspberry pie cm3
Lori remote control LEGO motor
每日一题——替换空格
Business modeling of software model | object modeling
Example 006: Fibonacci series
Synchronization of QT multithreading
Explore the authentication mechanism of StarUML
剑指 Offer 06. 从尾到头打印链表
STM32 virtualization environment of QEMU
Count the number of inputs (C language)