subject

You will write a method that checks a given expression (a String) with characters and brackets ("()", "[]", "{}", "<>"), determine if it is well-formed by using the following algorithm in conjunction with a stack.

• Check the expression character by character. If the character is an opening bracket (characters ‘(‘, ‘[‘, ‘{‘, ‘’), then:
• Check if the stack is empty. If it is, then there is no matching opening bracket. The expression is not well formed.
• If the stack is not empty, pop the top character off the stack, compare the current closing bracket to the top character. If they are matched brackets, continue to read next character in the expression; if they are not matched brackets, the expression is not well formed.
• If the end of the expression is reached, check if the stack is empty. If it is, the expression is well-formed. Otherwise, it is not well-formed.
• Your code should print meaningful error message when the expression is not well-formed. For example, "missing open bracket" if current character is a close bracket but stack is empty, "missing close bracket" if the end of string is reached but stack is not empty, or "mismatch brackets".

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 09:30
Which of the following tasks is an audio technician most likely to perform while working on a nature documentary? (select all that apply). eliminating potentially distracting background noise adding sound effects making sure the lighting is adequate for a particular scene changing the narration to better match the mood of the documentary
Answers: 3
question
Computers and Technology, 24.06.2019 00:00
Consider the series where in this problem you must attempt to use the ratio test to decide whether the series converges. compute enter the numerical value of the limit l if it converges, inf if it diverges to infinity, minf if it diverges to negative infinity, or div if it diverges but not to infinity or negative infinity.
Answers: 1
question
Computers and Technology, 24.06.2019 20:00
Avirus enters a computer or network as code embedded in other software directly from another computer
Answers: 1
question
Computers and Technology, 25.06.2019 05:30
Two technicians are discussing a resistance measurement. technician a states that components being measured should be removed or isolated from the circuit. technician b states that power to the circuit should be disconnected when measuring resistance. which technician is correct?
Answers: 1
You know the right answer?
You will write a method that checks a given expression (a String) with characters and brackets ("()"...
Questions
question
Mathematics, 19.04.2021 14:00
question
English, 19.04.2021 14:00
question
Mathematics, 19.04.2021 14:00
question
Mathematics, 19.04.2021 14:00
question
Mathematics, 19.04.2021 14:00
question
Mathematics, 19.04.2021 14:00
question
Mathematics, 19.04.2021 14:00
question
Mathematics, 19.04.2021 14:00
Questions on the website: 13722367