package com.hithomelabs.princeton1.module5;

/*
 * * Selection sort "selects" the smallest element and swaps it with arr[0] of the array
 * * Then proceeds to do the same swapping arr[i] with arr[i:arr.length-1]
 */
public class Selection<E> extends AbstractCustomSorts<E>{
    @Override
    public void sort(E[] arr) {
        int N=arr.length;

        for(int i=0; i<N; i++){
            int min=i;
            for(int j=i+1; j<N; j++){
                if(less((Comparable<E>) arr[j], arr[min]))
                    min=j;
            }
            exch(arr, min, i);
        }
    }
}

