On this code which contains a class implementing selection s
On this code which contains a class implementing selection sort. This class relies on its Comparator when it sorts data. Complete the selectionSort() method to use the selection sort algorithm to order the first selectionNumber elements in the array.
Code:
Solution
import java.util.Comparator;
/**
 * This class defines a single public method which performs one be used to sorts an array using selection-sort.
 *
 * @author Matthew Hertz
 * @param <E> Type of data which instances of this class will be sorting.
 */
 public class SelectionSort<E> {
/** Comparator instance we will be using to sort our data. */
 private Comparator<E> comp;
/**
    * Creates a new instance of this class which will be used to sort members of an array.
    *
    * @param theComp Comparator instance we will be using for our sorting.
    */
 public SelectionSort(Comparator<E> theComp) {
     comp = theComp;
 }
/**
    * Sorts the smallest {@code selectionNumbers} number in the array using selection sort. While it is unusual to
    * terminate midway through the sorting process, this is useful when an instructor needs to write unit tests which
    * verify students correctly implemented selection sort (and is nearly the same as writing the entire method!).
    *
    * @param x Array whose contents are to be sorted.
    * @param selectionNumbers Specifies the number of items that should be ordered using the selection sort algorithm.
    */
 public void selectionSort(E[] x, int selectionNumbers) {
     for (int i=0; i<selectionNumbers; i++){
       E min = x[i];
       int min_index = i;
       for (int j=i+1; j<x.length; j++){
         if (comp.compare(min, x[j])>0){
           min = x[j];
           min_index = j;
         }
       }
       x[min_index] = x[i];
       x[i] = min;
     }
 }
 }

