package com.hithomelabs.princeton1.module5;

public class Insertion<E> extends AbstractCustomSorts<E> {

    public void sort(E[] arr){
        if (arr == null) return;
        else{
            int N = arr.length;
            // * * swap arr[i] with each element greater to it's left
            for (int i = 1; i < N; i++){
                int j = i;
                while(j >= 1 && less((Comparable<E>)arr[j], arr[j-1])){
                    exch(arr, j, j-1);
                    j = j-1;
                }
            }
        }

    }


    }

