0

Java Help!

A stack is useful in the analysis of expressions to check if there are unbalanced symbols, because we know that when finding a closing symbol like), it must correspond to the opening symbol (more recent that is not yet closed.) Java programming and the data structure stack, implement the following algorithm: 1. create an empty stack. 2. read the symbols until the end of the file a) If the syntactic element is an opening symbol, insert it into the. stack. b) If it is a closing symbol and the pilá is empty, inform that an. error has occurred. c) Otherwise, remove an element from the stack, If the extracted symbol is not the corresponding opening symbol, report an error. 3. At the end of the file, if the stack is not empty, report an error.

17th Oct 2018, 3:49 PM
Ismael Miranda
Ismael Miranda - avatar
1 Réponse
0
This looks like a school homework question. If we give you the answer directly, we ruin your learning. . You must have the basic already, so can you please at least try to code a version here and so we can give you guideline based on your version? . If in case, you don't have any idea at all, you can refer to this lesson: Stack Interview Questions https://www.sololearn.com/learn/11883/?ref=app Although it's in Python, the framework is the same: Define push() and pop() to operate on the stack. Stack is initialized as an empty array. The only difference is you run for loop on every char of the file and add some if-statements, to push/pop according to the question requirements. It's really not so hard. I believe you can do it. Wait to see your work.
17th Oct 2018, 4:23 PM
Gordon
Gordon - avatar