Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider a stringsthat contains a pair of matching parentheses with zero or more characters between the parentheses. Examples of such strings include: '()' 'a(bcd)efg' 'The

Consider a stringsthat contains a pair of matching parentheses with zero or more characters between the parentheses. Examples of such strings include:

'()' 'a(bcd)efg' 'The professor (and her research assistant) solved an important problem.' 'x + ((y + z) / 2) * 10' 

Notice that the last example string contains a pair of nested parentheses.

Write a recursive functionget_enclosed(s)that returns the part of the stringsthat is enclosed by the outermost pair of matching parenthesesincluding the parentheses. For each of the example strings shown above your function should return the following strings:

'()' '(bcd)' '(and her research assistant)' '((y + z) / 2)' 

Your function does not need to handle strings where there are two or more pairs of matching parentheses that are not nested. Examples of such input strings that you can ignore are:

'(*^-^)(^-^*)' 'a(bcd)(efg)hij(klm)' '(x + y) * (y + z)' 

Finally, if the string does not contain a matching pair of parentheses then your function should return the empty string''. Examples of such input strings include:

`(` `)` `abcdefghi` `abc[def]ghi` 

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

=+Are the goals mutually achievable?

Answered: 1 week ago