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)

C++ Programming (C++14 standard) ***************************************************************************** Here are the situations where a mismatch

*****************************************************************************

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.

********************************************************************************************************************************************

occurs. 1. The next character is a right bracket and the stack

# 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

is empty; or 2. The next character is a right bracket and

#include #include #include #include "bracketMatcher.h"

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 S;

}

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 index and right bracket> or Unmatched bracket at index

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!