Question: Please only do #2(For a given stack, only use stack data structure to sort the stack in an ascending order.) ____________________Source Code___________________________________________ import java.util.*; public

Please only do #2(For a given stack, only use stack data structure to sort the stack in an ascending order.)
____________________Source Code___________________________________________
import java.util.*; public class Quiz1CS3 { public static void main(String[] args) { System.out.println(" Wednesday's Quiz!"); char[] wed = {'B', 'A', 'B', 'C', 'C', 'A', 'D', 'E', 'F', 'C', 'E', 'F', 'G', 'H', 'I', 'H', 'I', 'C', 'C', 'Z', 'W', 'X', 'W', 'X'}; countFrequence(wed); sortedStack(wed); delete(wed); } //This is a function to count the frequency of each character. public static void countFrequence(char[] cs){ //count the frequency of each charter use Hash. System.out.println("My counter List:"); //System.out.println(tMap); ////print out your result } //This is a function to print a sorted stack public static void sortedStack(char[] cs){ //Put the array into a stack. Stack myStack = new Stack(); for(int i= 0; i sortedStack = new Stack(); //finish some code here, you need to sort the original stack in an acceding order. //only use stack data structure to solve it. //print out your sorted stack System.out.println("My Sorted Stack is: "+ sortedStack.toString()); } public static void delete(char[] cs){ //put the array in a linked list. LinkedList myList = new LinkedList(); for(int i= 0; i(cs[i])); } System.out.println("My original List"); myList.printList(); //delete the last element in the list and use recursion.. myList.deleteLast(myList.head); //finish the method in LinkedList class below. System.out.println("List after deletion"); myList.printList(); } } //LinkedList class, you need to finish one method below. class LinkedList{ Node head; public LinkedList(Node head) { this.head = head; } public LinkedList() { this.head = null; } public Node last(){ Node l=head; if(l == null) return null; while (l.next != null){ l=l.next; } return l; } /** Add Node "n" means add at the end of the list **/ public void add( Node n){ if(head == null){ head =n; } else{ Node l=this.last(); l.next=n; } } /** Print this LinkedList **/ public void printList(){ Node n=this.head; if(n == null){ System.out.println("Empty List\t"); } else{ while (n.next != null){ System.out.print(n.getData()+" "); n=n.next; } /* Take care of the last node */ System.out.println(n.getData()+" "); } } //Delete last element in the list, code here using recursion. public Node deleteLast(Node head) { return head; //finish the code and return head } } //Node class, no need to change. class Node{ E data; Node next; Node(E data, Node next){ this.data = data; } Node(E data){ this.data = data; this.next = null; } public E getData() { return data; } } Lab Quiz 1 Policy: Open book exam and open to internet but you are not allowed to share your code with each other. Must be done individually in the lab room with the allocated time. Inform the TA if you've finished. Exam Questions: 1. Use a java built-in hash structure to count the frequency of each character for the given array. 2. For a given stack, only use stack data structure to sort the stack in an ascending order. 3. Use recursion to delete the last element in a LinkedList. Submission: submit this file to Brightspace after you've finished. 1. Take a screenshot of your output and paste it in the following table. 2. Copy and paste the three methods you've written in the following table. Answer sheets: (see next page) Student's Name: Sample output (this only a sample, not the solution) My counter List: My original Stack: [B,A,B,C,C,A,D,E,F,C,E,F,G,H,I,H,I,C,C,z,W,X,W,x] My Sorted stack is: [1] original List B A BCCADEF CE FGHI H ICCZWXWX List after deletion B A BCCADEFCEFGHIHICCZWXWX
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
