C/C++ Arena

Step 6 of 6

Challenge: balanced brackets

std::stack<T> gives you push, top, pop and empty. It's the right tool for matching brackets: push each opener, and each closer must match the most recent opener.

Your turn: write bool balanced(const std::string& s) for (), [] and {}. Other characters are ignored.

Previous: pair and tuple