Question: Write a recursive function that evaluates a Queue as a mathematical expression. This queue can have any of the following characters: { '(', ')', '+',

Write a recursive function that evaluates a Queue as a mathematical expression. This queue can have any of the following characters: { '(', ')', '+', '*'} or any single digit number. Evaluate this expression and return the result. For example, for the expression: "(((1+2)*(3+1))+(1*(2+2)))", each of these characters would be in the. As you recursively evaluate characters from the expression, you will remove the characters from the q. After evaluating the above expression, you should return 16. You are guaranteed that there are NO two digit numbers, and that the expression is well formed (parenthesis match, etc...). Do not use any loops. Do not use any data structures besides the q passed in as a parameter. @param q @return The result of the mathematical expression.

public static int evaluate(Queue q) {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!