Question
Given following recursive selection sort program and the array (it is called list in the main method), show a hand trace of following variables until
Given following recursive selection sort program and the array (it is called list in the main method), show a hand trace of following variables until the whole list is sorted. Initial values of the hand trace are already given. (10 points) low high indexOfMin min 0 8 0 22 public class RecursiveSelectionSort { public static void sort(double[] list) { sort(list, 0, list.length - 1); // Sort the entire list }
public static void sort(double[] list, int low, int high) { if (low < high) { // Find the smallest number and its index in list(low .. high) int indexOfMin = low; double min = list[low]; for (int i = low + 1; i <= high; i++) { if (list[i] < min) { min = list[i]; indexOfMin = i; } } // Swap the smallest in list(low .. high) with list(low) list[indexOfMin] = list[low]; list[low] = min; // Sort the remaining list(low+1 .. high) sort(list, low + 1, high); } } public static void main(String[] args) { double[] list = {22, 13, 17, 51, 22, -14, 30}; sort(list); for (int i = 0; i < list.length; i++) System.out.print(list[i] + " "); } }
Write a Java method using following method header to count and return the number of times a particular character appears in a text file. (10 points) public int charCount(char ch) Hint: following Java statements may help. File f = new File (filename); FileInputStream inf = new FileInputStream(f); char let; int n = 0; while ((n = inf.read()) != -1){ let = (char)n;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started