Home CPSC 340

Lab 3: Matching Parenthesis


 

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 © 2024 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.