本文介绍了如何写像&QUOT字符串的评估;(1 + 3 *(5/4)),并得到一个数值结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个面试问题
我感到困惑的解决方案,我想,我需要堆栈推动和弹出这些操作符和操作数,
但我需要两个堆栈,一个是运营商,一个用于操作数?或将只是一个堆栈呢?我认为,我们需要两叠,但有什么办法用一个堆栈来解决?

this is a interview questioni am confused about its solution, i am thinking that i need stacks to push and pop these operators and operands,but do i need two stacks, one for operator and one for operands? or would just one stack do?i think we need two stacks but is there any way to solve using one stack?

另外,我有点糊涂了如何将这项工作,每次我得到一个运营商,我会弹出我的两个最上面的操作数和操作数堆栈推的结果。

also i am bit confused how would this work, each time i get an operator i would pop two of my topmost operands and push the result in the operand stack

在preferance的括号,然后再划分,multioply和最后一个减法,然后加入

the preferance is brackets first,then divide,multioply and last subtraction and then addition

但如何检查时,弹出两个操作数,并做必要的arthimetic操作?

but how to check when to pop the two operands and do the necessary arthimetic operation?

推荐答案

看看的的。

在调度场算法是
  解析数学方法
  中缀表示法指定方程。
  它可用于产生输出的
  逆波兰式(RPN)或作为
  抽象语法树(AST)。该
  算法是由Edsg​​er发明
  Dijkstra算法并命名为调车场
  算法,因为其操作
  类似于铁路调车
  院子里。

这篇关于如何写像&QUOT字符串的评估;(1 + 3 *(5/4)),并得到一个数值结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:52