**Discussion 11: Stacks**
11/03 (election day holiday), 11/05
[(back to course webpage)](./mcs360_fall2020.html)
# Exercise 1
Given a string of parantheses, write a function that returns `true` if it is balanced, and `false` if it is unbalanced. For example, `(())()` is balanced but `)(` and `())` and `()(` etc. are unbalanced.
Think of an algorithm that uses stacks to solve this problem!
## Algorithm `isStringBalanced(string s)`
+ Create a stack of characters, `stk`. Loop through `i=0` to `s.length()-1`:
* If `s[i] == '('` push `s[i]` on the top of `stk`.
* If `s[i] == ')'` and `stk` is empty, return `false`.
* If `s[i] == ')'` and `stk.top() == '(', do `stk.pop()`.
+ After looping through the string, we want `stk` to be empty. If `!stk.empty()`, return `false` (this means there were too many opening parantheses). Otherwise, return `true`.
## Solution
```cpp
#include