Find Us On:

# java assignment

Read: https://en.wikipedia.org/wiki/Shunting-yard_algorithm Question: Write a program that inputs a string similar to: 3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3. Your program should apply the Shunting-yard algorithm to this string to ultimately produce a mathematical result. IMPORTANT***:Small Questions for the expert after the assignment is completed: 1) Which parts of the assignment were you not able to complete fully? For each, explain why you were unable to complete this part and what steps you took to attempt to complete it. Give me as much detail as possible such that I may award partial credit where it is due. 2)what would you do differently if you could do this assignment again? Attachments
Tags
Clarifications

## Solution for the Shunting Yard Algorithm Expression

mariobeka

Below you will find the java files containing the implementation of the algorithm as well as a screen shot of the program running. Attachments
Solution.zip (15 K)

Preview
The algorithm will only work if all numbers, functions and the parenthesis are divided with a white space. For example 2 + ( 3 * 5 ). I was unnable to complete

Preview
4 * 2 )"; String postfix = shuntingYard.parseAndEvaluate(input); System.out.println(input+" ->

Preview

Preview
= new Stack<String>(); for (String token : input.split("\\s+")) { // operator if (operation.containsKey(token)) { while (!stack.isEmpty() && hasHigherPrecedence(token, stack.peek())) { String pop = stack.peek(); output.append(stack.pop()).append(' '); values.push(evaluateFunctions(pop, Integer.parseInt(values.pop()), Integer.parseInt(values.pop()))); } stack.push(token); // left parenthesis } else if (token.equals("(")) { stack.push(token); // right parenthesis } else if (token

Screenshots