Question
C++ Programming (C++14 standard) ***************************************************************************** Here are the situations where a mismatch occurs. 1. The next character is a right bracket and the stack is
C++ Programming (C++14 standard)
*****************************************************************************
Here are the situations where a mismatch occurs.
1. The next character is a right bracket and the stack is empty; or
2. The next character is a right bracket and the top of the stack is not a match
3. You are at the end of the string and the stack is not empty; in this case the mismatch index is the length of the string.
********************************************************************************************************************************************
# Ifndef _MBRACKET_ # define _MBRACKET_
#include
using namespace std;
bool is_left(char c);
bool is_right(char c);
bool matches(char L, char R);
bool balanced(string str);
#endif
#include
string left_brackets("[({"); string right_brackets("])}");
bool is_left(char c) { return left_brackets.find(c) != string::npos; }
bool is_right(char c) { return right_brackets.find(c) != string::npos; }
bool matches(char L, char R) { assert(is_left(L) && is_right(R)); return left_brackets.find(L) == right_brackets.find(R); }
bool balanced(string str) {
// COMPLETE CODE HERE stack
}
You are to write a function to determine if the brackets ([1 ) are properly nested, i. e., balanced. The function will have a string as a parameter that can contain bracket and other characters. If the brackets are properly nested, the function will print the message The brackets in your string are properly matched Otherwise, it will print a message like this: Bracket mismatch at indexStep 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