Home CPSC 340

Lab 5: Matching Parenthesis

 

Due: September 25


 

Objective

To be able to utilize stacks in a Java program.


 

Task

For this lab, you will write a program that checks whether a string of parentheses and brackets is well-formed or not. The strings will be considered well-formed if each opening parenthesis/bracket is matched with exactly one closing parenthesis/bracket.

For example, the following strings are well-formed:

While the following are not:

This problem is best solved with a stack. The basic idea is to store the opening symbols on a stack. When you see a closing symbol, pop off the next opening symbol and make sure it matches. When done, ensure the stack is empty.


 

Details

 

Submitting

When you're finished, please submit your code for this lab on Canvas.

Copyright © 2020 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.