Data Structures
PA 03
Using a Stack
Due by Wednesday, October 7th at the start of class
Deadline extended until Friday, October 9th
[Code and paperwork due at the start of class]
Part A: Checking for a palindrome
- Create a file called pa03.py and write a method called palindromeChecker()
- This method takes a single String as a parameter and uses a Stack (or
perhaps more than one Stack) to determine if the alphabetical characters in
that String form a palindrome (for the sake of
this assignment we will ignore punctuation and spaces).
- The rules:
Part B : Validating html
- In a file called pa03.py create a method called htmlChecker()
- htmlChecker() takes a single (presumably long) symbol string as a
parameter
- htmlChecker() returns True or False depending on whether or not the the
symbol string was "valid" HTML where "valid" is defined as:
- A valid HTML string consists of HTML tags and page content
- An HTML tag is a tag contained between "<" and ">" For
example, <html> <body>
and even <1234> would all be considered HTML tags
in this assignment
- Every HTML tag comes in a pair - opening and closing tags. A
closing tag is the same as an opening tag with the addition of the forward
slash (/) between the "<" and the name of the tag. Thus,
</html> </body>
and </1234> are the closing tags for the opening
tags provided earlier
- HTML tags must be balanced. This is defined as
- An opening tag must occur before the occurrence of a closing tag
- Any opening tag that occurs "inside" (between) another set of tags
MUST also be closed within that set of tags as well.
- Thus:
- <a> <b> </b> </a> is
balanced since the opening and closing of b happens entirely inside
of the a-tags
- <a> <b> </a> </b> is not balanced
since the b-tag opens but does not close inside of the a-tags
- <a> </a> <b> </b> is balanced since
the there are no tags within either the a or b-tags
- HTML may contain content-data between tags. Thus,
- <a> <b> VALID </b> </a> is
valid, although technically
- <a> <b> </b> </a> INVALID
is not since the content
is completely outside of tags.
- Remember that putting that entire block of code between a pair of triple
quotes will allow you write strings that cross multiple lines.
Hints about solving this:
Bonus
TECHNICALLY, the content within tags could contain "<" and ">" For
example, the following would be valid HTML
<A> <B> 2<3 </B> <A>
For the basic assignment you may assume that "<" and ">" are ONLY used in tag
definition. For the bonus points, you should allow Strings such as that
given above. The one restriction that we will put on this is that "<" and
">" will not appear in the SAME block of content.
Submitting your assignment
To get full credit for this assignment you
must:
- Produce pa03.py that meets the requirements described above
- Use any implementation of the Stack contained in
stacks.py that you used in lab06 (depending on which one you chose, you
may also need node.py or arrays.py).
You may not modify these files.
- Upload your pa03.py by the deadline
- Submit paper printouts of pa03.py files by the deadline