#include #include using namespace std; int isBracketsMatched(string a) { stack stk; size_t len = a.length(); //cout << len << "\n"; char inv = ' '; for (size_t indx = 0; indx < len; indx++) { char ch = a[indx]; if (ch == '[' || ch == '{' || ch == '(') { stk.push (ch); } else if (ch == ']' || ch == '}' || ch == ')') { if (ch == ']') { inv = '['; } else if (ch == '}') { inv = '{'; } else { inv = '('; } if (inv == stk.top()) { stk.pop(); } else return 0; } } if (stk.empty()) return 1; else { cout <<"\nstack not empty"; return 0; } } int main() { cout << isBracketsMatched("[(5+4)*{(5/7)-(5+(8/4))}]"); return 0; }