package Sorting;

//import java.util.Arrays;
//import java.util.List;

public class InsertionSorter extends Sorter{
    
    public InsertionSorter(String filename){
        super("insertion", filename);
    }

    void sort(){
        int insertionValue;
        for(int i=1;i<numbers.length;i++){
            insertionValue=numbers[i];
            int j=i-1;
            while(j>=0 && compare(numbers[j],insertionValue)>0){
                numbers[j+1]=numbers[j];
                j--;
            }
            numbers[j+1]=insertionValue;
        }
    }

    
    /*
    //This method uses a List for simple insertion
    //But I want to go C-style and just do array manipulation
    void sort(){
        List<Integer> nums = Arrays.asList(numbers);
        for(int i=1;i<nums.size();i++){
			int j=0;
			while((j<i)&&(nums.get(i).compareTo(nums.get(j))>0)){
				j++;
			}
			if(j!=i){
                swapsUsed++;
				nums.add(j, nums.remove(i));
			}
        }
        nums.toArray(numbers);
    }*/
        
}