Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save graphoarty/25765a04738f1cd4a18a7b7939d88344 to your computer and use it in GitHub Desktop.
Save graphoarty/25765a04738f1cd4a18a7b7939d88344 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
void shell_sort(int L[], int length){
int gap = length / 2;
while(gap > 0){
int j = 0;
for(int i = gap; i < length; i++){
int temp = L[i];
for(j = i; j >= gap && L[j - gap] > temp; j -= gap){
L[j] = L[j - gap];
}
L[j] = temp;
}
gap = gap / 2;
}
}
int main(){
int L[] = {12, 34, 54, 2, 3};
int length = 5;
shell_sort(L, length);
for(int i = 0; i < length; i++){
cout << L[i] << " ";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment