3.ShellSort - C++
3.ShellSort - C++
#include <iostream>
void shellSort(int a[], int size) {
int i, j, temp;
int gap = size / 2;
while( gap > 0 ) {
for( i=gap; i<size; i++ ) {
temp = a[i];
j = i;
while( j>=gap && a[j-gap]>temp ) {
a[j] = a[j-gap];
j -= gap;
}
a[j] = temp;
}
gap /= 2;
}
}
int main() {
int arr[] = {9,1,22,4,0,-1,1,22,100,10};
int size = sizeof(arr)/sizeof(int);
shellSort(arr, size);
for(int x: arr) std::cout << x << " ";
}
Leave a comment