Question: How can I call the method selectionSort and insertionSort to my main method, so I can use them to sort and an array of integers
How can I call the method selectionSort and insertionSort to my main method, so I can use them to sort and an array of integers that are randomized? The methods I want to call are in a class called ArraySorter, which is a generic class.
Below are the two methods:
// SELECTION SORT /** Sorts the first n objects in an array into ascending order. @param a An array of Comparable objects. @param n An integer > 0. */ public static
return indexOfMin; } // end getIndexOfSmallest
// -------------------------------------------------------------------------------
// INSERTION SORT public static
public static
private static
// -------------------------------------------------------------------------------
Below is the code in my main method where I am creating the array and where I want to call the two methods to sort the array by selection and insertion.
import java.util.Arrays;
public class client {
public static void main(String[] args) { int[] array = new int [10]; for (int i = 0; i < array.length; i++) array[i] = (int)(Math.random() * 100); System.out.println(Arrays.toString(array));
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
