@Override
    public void sort(SorterParams sParams)
    {
    
        int[] theArray = sParams.getArrayToSort();
        int[] gapArray = sParams.getGapArray();
        
        MemoryUsage.addMem(gapArray.length);
        
        MemoryUsage.addMem(1);
        for(int k = 0; k < gapArray.length; k++)
        {
            MemoryUsage.addMem(1);
            for(int i = gapArray[k]; i < theArray.length; i++)
            {
                int currentVal = theArray[i];
                int j = i - gapArray[k];
                MemoryUsage.addMem(2);
                if(sParams.getDirection() == SorterParams.SortDirection.ASCENDING)
                {
                    while(j >= 0 && theArray[j] > currentVal)
                    {
                        theArray[j + gapArray[k]] = theArray[j];
                        j -= gapArray[k];
                    }
                    theArray[j + gapArray[k]] = currentVal;
                }
                else
                {
                    while(j >= 0 && theArray[j] < currentVal)
                    {
                        theArray[j + gapArray[k]] = theArray[j];
                        j -= gapArray[k];
                    }
                    theArray[j + gapArray[k]] = currentVal;
                }
                MemoryUsage.removeMem(2);
            }
            MemoryUsage.removeMem(1);
        }
        MemoryUsage.removeMem(1);
    }