We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/chapters/chapter-1-fundamentals/1.3-bags-queues-ans-stacks/evaluate.js
双栈算法表达式求值算法,例如 ( 1 + ( ( 2 + 3 ) * ( 4 + 5 ) )
( 1 + ( ( 2 + 3 ) * ( 4 + 5 ) )
The text was updated successfully, but these errors were encountered:
下面是算法。
function evaluate(input) { input = input.reverse(); var len = input.length; var optStack = []; var valStack = []; while(len--) { var item = input[len]; switch(item) { case "+": case "-": case "*": case "/": optStack.push(item); break; case "(": break; case ")": var a = valStack.pop(); var b = valStack.pop(); var opt = optStack.pop(); valStack.push(eval(a + opt + b)); break; default: valStack.push(item); } } return valStack.pop(); }
临时给自己的一个思考题:( + 1 ( * ( + 2 3 ) ( + 4 5 ) ),这个问题如何处理?
( + 1 ( * ( + 2 3 ) ( + 4 5 ) )
Sorry, something went wrong.
Merge pull request #3 from barretlee/master
4f64814
Merge pull request #18 from StevenYuysy/master
No branches or pull requests
/chapters/chapter-1-fundamentals/1.3-bags-queues-ans-stacks/evaluate.js
双栈算法表达式求值算法,例如
( 1 + ( ( 2 + 3 ) * ( 4 + 5 ) )
The text was updated successfully, but these errors were encountered: