Question: Checking order or Parenthesis Problem Java Problem 1: Using a stack to check order of parenthesis (20 points) In this program, you will read your
Checking order or Parenthesis Problem Java

Problem 1: Using a stack to check order of parenthesis (20 points) In this program, you will read your inputs from a file input.txt, which will contain multiple lines with different sequences of brackets. You task is to create a class ParenthesisMatch.java, with two method s isParenthesisMatch and main. The main method will read the input.txt file, which will contain the following example inputs. The main method will read each line from the file, and pass the string to the isParenthesisMatch method. The isParenthesis method will check if the order of the parenthesis is valid, and will return a Boolean true/false. E.g. for the above lines, the outputs will be true true true true false false false The above problem can be easily solved using a stack. The algorithm is that, as you scan each character in the string of parenthesis, every time you see a '(', then you push it in the stack. Otherwise, if you see a '),, you check if the current top of stack ?s('Jfitis, then you pop it out of the stack. Otherwise, if the stack is empty, or if the current top is not you return false. Finally, when all the characters in the string is scanned, and if the stack is empty, you return true. Otherwise, if the scanning of the string is competed, but the stack is not empty, you return false. Use the pseudocode below to solve the problem as described For each character C in string of parenthesis If C is then push C in stack Else if C is')', thern If stack is empty, then return false Else if top of stack is (', then pop element from stack Else return false Return true if stack is empty, or false otherwise
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
