Question: Using Java, implement a stack on the singly linked list with the operations: push, pop, top, size, isEmpty. Make sure that your program checks whether
Using Java, implement a stack on the singly linked list with the operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. Hint: The functionality of push and pop is now based on the methods of the linked list class.
4. Practical application 1: Balanced parentheses.
(a) Using the singly linked list implementation of the stack design an algorithm which represents an arithmetic operation, as input and checks whether or not the brackets are correct (balanced) or incorrect (unbalanced). The input string may contain a combination of the following characters: {,},[,],(,),0,1,2,3,4,5,6,7,8,9,+,-,*,/. Your algorithm must not check the correctness of the arithmetic operators/operands, but only check for balanced brackets. Your algorithm should also show an error message when the string contains a character that is not one of those listed above.
(b) Explain how your algorithm checks for balanced parenthesis in O(n), when the input is a string of length n.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
