[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
[CS152 2005S]
[CS152 2005F]
Assigned: Wednesday, March 8, 2006
Due: 8:00 a.m., Tuesday, March 14, 2006
Summary: In this assignment, you will apply stacks to the problem of matching parentheses. vectors.
Purposes: To get you used to using stacks.
Contents:
In the lab on stacks, you wrote a program that used a stack to ensure that the parentheses in an expression are matched. Extend that program to print out the matches for a single-line expression. For example,
(oh (boy) (I am having) ((so) much) fun matching (parens))
+---+
+-----------+
+--+
+---------+
+------+
+--------------------------------------------------------+
Your program should also handle erroneous inputs. For example,
())((opened closed) (opened (opened closed) (opened
++
?EXTRA CLOSE
+-------------+
+-------------+
+------MISSING CLOSE
+------------------------------MISSING CLOSE
+-----------------------------------------------MISSING CLOSE
Keep track of your position within the string. When you encounter an opening paren, push the position. When you encounter a closing paren, pop the position and print the string.
You will benefit from a helper method to print the string. You can use a for loop or build a really long string of spaces (and a really long string of dashes), and use substring to extract the proper number of spaces or dashes.
Email me your program.
Wednesday, 8 March 2006 [Samuel A. Rebelsky]
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[On Teaching and Learning]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[SamR]
[Java 1.5 API]
[Espresso]
[TAO of Java]
[CS152 2004F]
[CS152 2005S]
[CS152 2005F]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Tue May 9 08:31:12 2006.
The source to the document was last modified on Wed Mar 8 09:11:55 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS152/2006S/Homework/hw.12.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby