CSC 241 Lab 3 Given an unsorted ArrayList of Integer values, write a recursive m
ID: 3906517 • Letter: C
Question
CSC 241 Lab 3 Given an unsorted ArrayList of Integer values, write a recursive method called smallestNumber that will find the smallest number within the ArrayList. The approach should use the fact that the smallest number in a subarray of the ArrayList is equal to the smaller of the first number in the subarray and the smallest number in the remainder of the subarray. The subarray will always contain the last item in the ArrayList. The method will take one parameter-the starting index of the subarray; it will also return the smallest number found. Create and test the smallestNumber method in a driver program given the following array -3,5, 1,-9,8, 16, 10, 4, 5,2,-1Explanation / Answer
import java.util.ArrayList; public class SmallestNumber { public static int smallestNumber(ArrayList list, int index) { if(index == list.size() - 1) { return list.get(index); } else { int min = smallestNumber(list, index+1); if(list.get(index)Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.