Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
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: 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started