CS206: Data Structures, Assignment #8

Stacks and Queues

The goal of this assignment is to:

ADT

We will design an ADT in class to implement a Stack. It should have an interface for the following functions:

Implementation

Create a Java class that implements the ADT.

Test

Write a series of tests to test each method. Test for failures and successes.

Solve Problems

Use your new stack class in another Java program to determine if the following expressions are valid. Valid expressions are made up of the following characters: "X()[]' (that is: double-quote, capital X, open paren, close paren, open bracket, close bracket, single quote, and space. Spaces can appear anywhere. If it contains a "'([ then the next non-X character must match, eg "')].

Note that if a quote or double-quote comes in, treat it as an ending, if the last on the stack is a matching quote. Otherwise, treat it as a starting symbol.

Some tests:

XXXXvalid
X X X Xvalid
X(XX)Xvalid
(XX)valid
(XX)[]valid
(["''"])valid
([)]invalid
"XXXX XXXX"valid
"XXXX XXXXinvalid
"(XXXX) (XXX)"valid
"XXXX" X "XXXX"valid
"XXX XXX (X) XXX XXX "XXX""valid

Think of some more problems to test your expression validator.