In JAVA Write a recursive version of Selection Sort, and then a non-recursive ve
ID: 3742272 • Letter: I
Question
In JAVA Write a recursive version of Selection Sort, and then a non-recursive version. Use words.txt as your input file and input the data into two arrays so you can use one array with each sort. Method to input into 2 arrays AT THE SAME TIME. (call this method once).Insert a timer so we can compare and see how long each sort takes. (Be careful to time only the sort and not the input or output) Sort the words.txt file once it is in an array. words.txt: noncollectable reallocation drenching obnoxious venality dybbuk shotgun changelessly handiwork timer: long startTime = System.nanoTime(); methodToTime(); long endTime = System.nanoTime(); long duration = (endTime - startTime);
Explanation / Answer
import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class SelectionSortTimes { public static int count(String filename) throws FileNotFoundException { int c = 0; Scanner fin = new Scanner(new File(filename)); while (fin.hasNext()) { fin.next(); c++; } fin.close(); return c; } public static void selectionSortIterative(String[] arr) { int minInd; String temp; for (int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.