Question: Your main focus is to implement the shunting-yard algorithm as described here: https://en.wikipedia.org/wiki/Shunting-yard_algorithm You most likely should not bother with the ^(exponential) operator. Start with
Your main focus is to implement the shunting-yard algorithm as described here: https://en.wikipedia.org/wiki/Shunting-yard_algorithm
You most likely should not bother with the ^(exponential) operator.
Start with a String of text tokens, each of which can be +,=,/,*,(,), or a number representing an infix expression.
Use the shunting yard algorithm to evaluate the expression. If your input line is
String theLine;
Then, you should be able to do the expressions one by one by doing something similar to this:
StringTokenizer(theLine, "+-/*() ", true);
The final true tells the tokenizer to create tokens of the various separators, so if you tokenize
theLine = "(10.0 + 12.0)/4.0 + 3.0";
your tokens will be something like
( 10.0
+
12.0 ) 4.0
+
3.0
You will need to get rid of any tokens consisting of only blank space.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
