Question: Write a program BalancedParentheses.java. The algorithm for evaluating parentheses is as follows: (a) Remove all non-parentheses from a mathematical expression. (b) Given an opening parenthesis,

Write a program BalancedParentheses.java. The algorithm for evaluating parentheses is as follows: (a) Remove all non-parentheses from a mathematical expression. (b) Given an opening parenthesis, 1.e., a '[', a (' or a ' {', push t onto the stack. (c) Given a closing parenthesis, pop an opening parenthesis from the stack: (i) if the closing parenthesis and the opening parenthesis match, it is a successful match (ii) if the parentheses do not match, the expression is not balanced (iii) if the stack is empty, the expression is not balanced (d) if, at the end of the program, the stack is empty, then the expression is balanced. For example: [3 + (2 - 4) + ((a - b))] is balanced, while [3 + 2( and {7+[a - bj ] are not balanced The main program should contain a test method that will test your program

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!