Answered step by step
Verified Expert Solution
Link Copied!

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.image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions