Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

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

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.

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

image text in transcribed

# 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

image text in transcribed

#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

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

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions