Created
March 3, 2019 03:07
-
-
Save graphoarty/25765a04738f1cd4a18a7b7939d88344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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