CSE 214 Lecture 11: Stack Algorithms
Document Summary
[] --> [(] -> [ (( ] => [ {(( ] -> [ (( ] -> [(] -> [] false since it is not balanced with 1 extra parenthesis on the right. Each time the iterator runs into a "(" or "{" character, it gets popped until it is empty. You can check for balance without a stack by using a counter by adding 1 to the counter for each "(" and subtracting 1 for each ")". The counter can never be negative or else the equation is not balanced or empty. Therefore, you remove the right most character in the string. You can use integers like 1 or 2 to denote for "(" and "{" respectively and use mod to get the remainder like 2 and divide by 10 to get rid of the right most number (the ones place).