Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(3) A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: - S is
(3) A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: - S is empty; S has the form (U)" or "[U]" or "U" where U is a properly nested string; S has the form "VW" where V and W are properly nested strings For example, the string "[00l"is properly nested but "(DO]" is not. Write a function: int is.nested (string S) that, given a string S, returns 1 if S is properly nested and 0 otherwise. For example, given string S-" 1", the function should return 1 and given S")]", the func- tion should return 0, as explained above. Write an efficient algorithm assuming that the string S consists only of the following char- acters: "(", "I', "r. up, "I' and/or ") . Write a program that requests a user to enter a string containing characters ", "[", "1". " " and/or"and then determines whether the string is nested. Implement a loop in the above actions are performed until the user requests to quit. . Hint: Use stack to solve the problem. Submit the solution as hmw.6.3.cpp . Sample input-output Select C Enter a string: [OO String [OO] is properly nested Continue y? Enter a string: ()O] String ([))] is NOT properly nested. Continue y? Enter a string: [Oo0OO0(o)]] String o0)]] is properly nested. Continue y? Enter a string: 11 String IC[[ is NOT properly nested Continue y? n Press any key to continue
Step 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