include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
bool bracketMatch(string str){
stack[HTML_REMOVED] s;
for(auto c : str){
if(c == ‘(‘ || c == ‘{‘ || c ==’[‘) s.push(c);
else{
if(s.empty()) return false;
char top = s.top();
if(top ==’)’ && c!=’)’ ||
top ==’}’ && c!=’}’ ||
top ==’]’ && c!=’[‘) return false;
}
}
return s.empty();
}
int main()
{
string s1 = “((()))”;
string s2 = “([{{}])”;
if(bracketMatch(s1))
cout << "s1 matched" << endl;
else
cout << "s1 not matched" << endl;
if(bracketMatch(s2))
cout << "s2 matched" << endl;
else
cout << "s2 not matched" << endl;
return 0;
}