栈实现四则远算
总结
四则运算表达式求值分两步
中缀转后缀,栈中存符号
后缀算结果,栈中存数字
中缀表达式与后缀表达式转换
中缀表达式1+(2-3)*4+5/6
后缀表达式1,2,+
通过栈进行转换
- 数字:直接输出
- (:进栈
- ):出栈直到(,弹出(
- 运算符:出栈(高阶等阶运算符),进栈(当前运算符)
后缀表达式的计算
数字进栈,符号远算
python实现
leetcode相关题目
1.https://leetcode.com/problems/basic-calculator/
2.https://leetcode.com/problems/basic-calculator-ii/
3.https://leetcode.com/problems/basic-calculator-iii/
4.https://leetcode.com/problems/basic-calculator-iv/