Question
I need a Java program that reads in a postfix expression, splits it into an array of strings and does just this so I can
I need a Java program that reads in a postfix expression, splits it into an array of strings and does just this so I can fully understand this excercise. It needs to deal correctly with parenthesized sub-expressions and operator precedence. A tree needs to be built to take the grammatical subtleties of the expression into account. Thank you!!!!
Evaluate a reverse polish (postfix) expression such as
2 * (3 + 4) + 5
then this will be parsed into a tree, and then the output in reverse polish notation (postfix notation) such as
2 3 4 + * 5 +
This can be interpreted by reading it from left to right once you see a number you can then push it on the stack, and when you see an operator, pop the right operand off the stack into a variable(r) and then pop the left operand off the stack into a variable(l), then using a switch on the operator combine (l) with (r) using the operator and push the result back onto the stack.
Essentially this can be completed by creating various parts in different classes of a tree i.e a stack, node, operatorenode, number node.
This excercise should be very simple but I just do not understand it I need help creating the program to understand this as my next project does need me to understand this. Thank You so much.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started