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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 21:40, gaby06
Simon says is a memory game where "simon" outputs a sequence of 10 characters (r, g, b, y) and the user must repeat the sequence. create a for loop that compares the two strings. for each match, add one point to user_score. upon a mismatch, end the game. sample output with inputs: 'rrgbryybgy' 'rrgbbrybgy'
Answers: 3
image
Computers and Technology, 24.06.2019 10:30, brandon1748
You're programming an infinite loop. what must you include in your code to prevent crashes? in roblox
Answers: 2
image
Computers and Technology, 24.06.2019 16:00, deepunalli300p3ur3i
Your is an example of personal information that you should keep private.
Answers: 2
image
Computers and Technology, 24.06.2019 17:40, orlandokojoasem1234
Write an assembly language program to input a string from the user. your program should do these two things: 1. count and display the number of words in the user input string. 2. flip the case of each character from upper to lower or lower to upper. for example if the user types in: "hello there. how are you? " your output should be: the number of words in the input string is: 5 the output string is : hello there. how are you?
Answers: 2
You know the right answer?
You will write a method that checks a given expression (a String) with characters and brackets ("()"...

Questions in other subjects:

Konu
Social Studies, 03.02.2020 05:58
Konu
Mathematics, 03.02.2020 05:58