← Back to STL Containers
Question 513
Balanced Brackets Three Kinds
Balanced Brackets Three Kinds
Write a functionbool isBalanced(const string& s)that uses astack<char>to check whether the brackets insare 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 printtrueorfalseon 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
Sign in to use hintsTopics:
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.