my teacher said that line for (int j = i - step; j >= 0; j = j - step) spoils the whole essence of sorting. he said that I need to use the inset sorting function and insert it into the shell sorting. How can I do this?
template < typename T >
void swap(T* arr, int j, int step)
{
T value = arr[j];
arr[j] = arr[j + step];
arr[j + step] = value;
}
template < typename T >
void shell_sort(T* arr, int length)
{
for (int step = length / 2; step > 0; step = step / 2)
{
for (int i = step; i < length; i++)
{
for (int j = i - step; j >= 0; j = j - step)
{
if (arr[j] > arr[j + step])
{
swap(arr, j, step);
}
}
}
}
}
for (int j = i - step; j >= 0 && arr[j] > arr[j + step]; j -= step)