Skip to content

Instantly share code, notes, and snippets.

@maxgoren
Created October 13, 2021 17:53
Show Gist options
  • Save maxgoren/54a14d25f22af6756c5cc108262505d1 to your computer and use it in GitHub Desktop.
Save maxgoren/54a14d25f22af6756c5cc108262505d1 to your computer and use it in GitHub Desktop.
template <typename T>
void shellSort(vector<T>& arr)
{
int N = arr.size();
for (int gap = N/2; gap > 0; gap /= 2)
{
for (int i = gap; i < N; i += 1)
{
int temp = arr[i];
int j;
for (j = i; j >= gap && arr[j - gap] > temp; j -= gap)
{
arr[j] = arr[j - gap];
}
arr[j] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment