As mentioned in class, computers don’t natively understand mathematical expressi
ID: 3853933 • Letter: A
Question
As mentioned in class, computers don’t natively understand mathematical expressions in the way we prefer to write them. While we prefer “infix” notation, where the operators come between the values being operated upon, computers prefer either “prefix” or “postfix” notation, as these are unambiguous and easier for them to operate upon. As the project, at its core, is to write a mathematical calculator, we will need to convert math expressions to one or the other at some point.
The requirement of this project stage is to implement the Shunting-Yard algorithm (http://en.wikipedia.org/wiki/Shunting-yard_algorithm) as it applies to the overall design of this project. You do not need to calculate any values – the goal is to simply turn any input infix expression into a postfix expression, an analysis that will aid the later stages of this project.
You may assume that there will always be spaces between any values and operators, as this can aid parsing and reduce the complexity of your input code.
Example input/output:
> 67 + ( 32 / 8 ) * 3 rt 8 67 32 8 / 3 8 rt * +
This is all we’re looking for in this project stage – no bells or whistles needed. Please keep the prompt as you see it in this example – just a leading “>” to request input
Explanation / Answer
Answer: to convert from infix to postfix uses a stack to compute any instruction or expression
Infix is the notation we use daily and postfix we convert fir computer here is the algorithm to convert
And the Java program to convert infix to postfix
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.