JAVA PROGRAMMING Parentheses Match Stacks A fairly common a
JAVA PROGRAMMING :
Parentheses Match
Stacks
A fairly common algorithmic task is to process some data set in reverse order. Typically you put some data in temporary storage, then take it out, always in a Last-In, First-Out (LIFO) order. A stack is the data structure that was invented to help manage this process. A real- world example of a stack is the dispenser of the trays in the lunch room. You always take the top tray from the top, never from the middle or the bottom. Similarly, the lunch workers always put trays on the top, never at the middle or bottom.
Algorithm
The task is to determine whether the grouping symbols--parentheses, brackets, curly braces, etc.--in an arithmetic expression, such as [(5+7)*3]), match each other. Ignoring all digits and operands, push the left-grouping symbols on the stack. When a right-grouping symbol is encountered, pop the stack. Somehow compare the two characters. If they don\'t match, return false. Somehow, determine the end of this process and return true if the expression has passed all the matches.
Requirements
Define a Stack ADT named CharStack.java, and use a linkedList to implement the ADT. The Stack ADT should have only one data member: LLNode top; (LLNode is provided).
Design a tester program named ParenthesesMatch.java, within this class, define a static method as specified in the following header to evaluate if a String has matching parentheses. If they don\'t match, return false. Somehow, determine the end of this process and return true if the expression has passed all the matches.
public static boolean checkParentheses(String s)
The String to be tested is passed to the program through command argument list.
Test Run
Solution
#include