Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

____________________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',

image text in transcribed

____________________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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago