Question: Nesting C++ Problem. We are only expected to turn in the function. If you can, keep out the fancy code techniques that make it obvious
Nesting C++ Problem. We are only expected to turn in the function. If you can, keep out the fancy code techniques that make it obvious a student like me didn't actually code it.



Nesting Highest grade: Editor Submitted Versions 1 #include 2 3 - bool is_valid(string expr, string left, string right) { 4 // fill in this method 5 } 6 Problem Statement In many contexts, certain delimiting characters or sequences occur in pairs. For instance, in mathematics, parentheses always occur in pairs: a left parenthesis with a right parenthesis. In books, it is common to have left and right quotation marks for setting off quotes. XML and other strict markup languages typically have special markers for the beginning and end of a piece of formatted text (e.g., "","" are put around text to make it bold in HTML). In more complex mathematical expressions it is common to have multiple types of delimiters to help keep things orderly; thus square brackets ("[]"), curly brackets ("{}") and more are employed. An important property of these delimiters is that they are always properly nested; you cannot have a left delimiter of one type between a pair of delimiters of another type without also having the right delimiter. More specifically, we can talk about the appearance of a left delimiter as creating a new context of a type specific to that delimiter. Each left delimiter takes us into a new, inner context. We can only leave the context specific to the most recent left delimiter, not any outer context. Additional rules for delimiter pairs are that they must occur in pairs in the proper order; you cannot have a left delimiter without a matching right delimiter, and vice versa, and you cannot have a pair in which the right delimiter comes first. Create a function is_valid, which takes three strings, expr, left, and right, and returns true if expr represents a valid expression as regards the proper nesting of the left and right delimiters contained in left and right. Here the delimiters are all single characters, so each index in left and right corresponds to one delimiter pair. Notes and Constraints expr contains between 0 and 50 characters, inclusive. Each character in left represents the left delimiter of a pair, and the corresponding character in right is the associated right delimiter. left and right contain between 0 and 5 characters, inclusive, and contain the same number of characters. left contains none of the same characters as right, and there are no duplicates in either string. Characters other than the delimiters are irrelevant to the problem and can be ignored. Examples Submit Examples 1. "(easy)" "(" 11 return true 2. "{(x + y) * z}" "(" ")}" return true Note how index 0 holds the matching pair of delimiters "(" and ")" in left and right. Index 1 holds' {" and "}" 3. "hello, world!" return true There are no delimiters here to test for, so the expression is automatically valid. 4. "abcdxDCBA" "abcd" "ABCD" return true TI Note how index 0 holds the matching pair of delimiters "" and ")" in left and right. Index 1 holds {" and "}". 3. "hello, world!" return true There are no delimiters here to test for, so the expression is automatically valid. 4. "abcdxDCBA" "abcd" "ABCD" return true For this problem, delimiters can be anything. Here "a" is a left delimiter with matching closing delimiter "A". 5. "COO)" "(" ")" return false There is a right delimiter with no matching left delimiter. 6. "({oops)}" "(" ")}" return false Improper nesting - the context opened by the left parenthesis closes before the inner context opened by the left curly brace