Computers and Technology

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".

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:30, aryal191
Primary tech skills are skills that are necessary for success in online education
Answers: 3
image
Computers and Technology, 23.06.2019 01:00, leo4687
Complete the sentence about a presentation delivery method
Answers: 2
image
Computers and Technology, 23.06.2019 11:30, magicalpenguin48
In cell h5 enter a formula that will calculate the percentage of attendees that went to the altamonte springs job fair in 2018.
Answers: 1
image
Computers and Technology, 25.06.2019 08:10, mil3ndy
What is the relation between information and data?
Answers: 3
Do you know the correct answer?
You will write a method that checks a given expression (a String) with characters and brackets ("()"...

Questions in other subjects:

Konu
History, 15.12.2020 01:00
Konu
Social Studies, 15.12.2020 01:00
Konu
Mathematics, 15.12.2020 01:00