Project #14.1: Write a program that reads in text from a file and tests to see if the parentheses are balanced — that is, for every left parenthesis '(' there's always one matching right parenthesis ')' later in the text.. Use a stack to keep track of the left parentheses.Extra: Also balance curly braces, square braces, and angle braces (i.e.,
<
and>
) as well, making sure the type of right brace matches the left brace you pop off.
Project #14.2: Use astack
to determine if astring
is a palindrome (i.e., it reads the same backwards as forwards).
Project #14.3: Use astack
to print out the "palindrome" of each word in a file. ("The palindrome of 'Boston' is 'Notsob'!") Read the file word by word and for each word reverse it using thestack
.
Project #14.4: Write a program that processes the endnotes in a file. In this file, the user uses[[
...]]
to indicate that the text between the braces is an endnote, and should actually appear at the end of the file. Read in the file and output immediately all of the normal text. For each endnote, store it in aqueue
until the end of the file is reached. Then output the endnotes.Extra: Automatically insert endnote numbers: for the first
[[
...]]
, output[1.]
in the document text and label the endnote with1.
in the list of endnotes. In general, for the ith[[
...]]
, output[i.]
in the document text and label the endnote withi.
in the list of endnotes.