CJCoding With Joseph
15free / daySign inCreate account

Balanced Brackets Three Kinds

Write a function bool isBalanced(const string& s) that uses a stack<char> to check whether the brackets in s are balanced. The string contains only the six characters (, ), [, ], { and }. Balanced means every opening bracket is closed by the same kind of bracket in the correct nesting order: ([]{}) and {[()]} are balanced, while ([)], (() and ] are not. The empty string counts as balanced.

The tests print true or false on its own line for each string tested. For ([]{}) the output is exactly what is shown in Expected Output.

Do NOT write a main function.

Expected Output:

true
false
false

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
STL ContainersStacks
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.