Question: Write a program to match parenthesis (), square braces [] and curly braces {}. Your program should use a recursive method that returns the number

Write a program to match parenthesis (), square braces [] and curly braces {}. Your program should use a recursive method that returns the number of pairs of each type of brace and return -1 if it is unbalanced for a particular pair. You should also create a Stack class that will be used by the method to match braces. Refer to Chapter 10.6 (page 380) for a sample Stack class.Write a program to match parenthesis (), square braces [] and curly

O MatchingBracesTestCases - Notepad File Edit Format View Help (a+b) (a+b*(c-d)) (e+f) (g-h) (a+b*[C-d])[e+f{g-h}] (a+b*[C-d])e+f{g-h}] > run MatchingBraces Enter String: (a+b) Matching () pairs: 1 Matching [] pairs: 0 Matching {} pairs: 0 > run MatchingBraces Enter String: (a+b*(c-d))e+f)(g-h) Matching (0 pairs: 4 Matching [] pairs: 0 Matching {} pairs: 0 > run Matching Braces Enter String: (a+b^[c-d])[erf{g-h}] Matching (1) pairs: 1 Matching [] pairs: 2 Matching {} pairs: 1 > run Matching Braces Enter String: (a+h*[e-d])e+f[g-h} Matching (0 pairs: 1 Unbalanced [] Matching (0 pairs: 1

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!