Question: Lab 4 This lab is to be completed individually This lab is for you to understand data structure such as Stack What to do? Task



Lab 4 This lab is to be completed individually This lab is for you to understand data structure such as Stack What to do? Task 1 Design and implement a simple stack for char. Two.java files are provided which are CharNode.java and CharStack.java. You are required to complete the classes with your design and implementation. Task 2 Design and implement a parentheses validator, isValid, in ParenthesesValidator.java. Given a string containing just the characters '(',')', '{', '}', 'l' and 'l', determine if the input string is valid. Return true if it is valid, otherwise, return false. An input string is valid if: 1. Open brackets must be closed by the same type of brackets. 2. Open brackets must be closed in the correct order. For example, both ([]{} and {[]} are valid parentheses, while () and ([)] are not. Please put your code between /* #. Filling your code here */ and /* #. End of code */. Follow the instructions in comments carefully. Do not change the code or structure outside the blocks. Make your own test cases to test the program. Char Node.java 28 CharNode.java > No Selection 1 public class CharNode 2 { 3 // Instead of implement a single function as before, You are required to design and implement the whole class. // Design and implement your CharNode. It's a link node which contains a char // You can define any attributes or methods on your own // You will use your CharNode class in CharStack. 11 10. Filling your code here // 10 End of your code 9 10 } Chars 8 CharStack.java) C class CharStack 1 2 3 Implement your own stack, CharStack, using Linked list. / You shall not use the default linked List eless free Java. / Element in CharStack as Charade which contain a char. public class CharStack protected Cher Mode top; public Churstuck top = null; Char Initialize me CharStack with a thar. W It was the steek will contain a lot, a Chazkode which earries the input cher. public CharStack char c) { 1. Filling your code HTH B CharStack.java) C class CharStack truturn the ther of the top wetent public char top1 { do Filling your code here 1. End of code 6. End of code W Initialize a new CharStack with a ekisting CharStack. It's copying the input CharStack and create a new one. Fint: // Do not modify the input CharStack public CharStack(charstack cs} { 2. Fill in your code INTH W return true 1' the stack is cepty, otherwise, return false; public boolean isEnpty() { 7. F111ing your code here }} 7. End of code 2. End of code My return the number of elements in the stack public int size 8. Filling your code here w Crwatsu CharStack. The newll contains all the chantar in input string. 8. End o code The last char in string shall be at the top of the stack. publie Chartek(Stringate { 13. Filling your code here transfer the stock to a string and return it. /E.Q. Fzor botton to the top, if the chars in stack are 'a', 'o', 'c': '!'. The return shall be acc!" publie String tastring() 9. Filling your code here 3. End ot code 10. End of code n puah a cher to the top of the stock public void push(char x){ // 4. Filling your code INH 14. End of code pop the top cher from the stack pty stock. For you convenience, you are not required to handle exception when poping a It means when e stack is erpty, do nothing public void pop() { 15. Filling your code INIH 5. En af rode // return the thor of the top element public chur tup() { . Filling your code here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
