#include <iostream>
using namespace std;
void shellSort(int a[], int n){
int i, j, pivotKey, gap;
for(gap = n/2; gap > 0; gap /= 2){
for(i = gap; i < n; i++){
pivotKey = a[i];
for(j = i - gap; j >= 0 && a[j] > pivotKey; j -= gap){
a[j + gap] = a[j];
}
a[j + gap] = pivotKey;
}
}
}
int main(){
int a[] = {5, 3, 6, 12, -11, 34, 100, 2, 0, 55};
shellSort(a, 10);
for(int i = 0; i < 10; i++){
cout << a[i] << " ";
}
cout << endl;
return 0;
}
希尔排序
最新推荐文章于 2023-11-28 16:53:17 发布