CSE 214 Lecture 11: Stack Algorithms

84 views2 pages
23 Sep 2016
Course
Professor

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).

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers