#include <iostream>
using namespace std;
int main()
{
int arr[] = {45,84,77,83,55,49,91,64,91,5,37,31,70,38,51};
int gap[] = {5,2,1};
int len = size(arr);
int current_gap;
for(int i=0; i<3; i++){
current_gap = gap[i];
for(int j=current_gap; j<len; j++){
int t = arr[j];
int k = j;
while(k>=0 && k-current_gap>=0 && arr[k-current_gap]>t){
arr[k] = arr[k-current_gap];
k -= current_gap;
}
arr[k] = t;
}
}
for(auto l : arr) cout<<l<<" ";
}
size()只有在C++17以上才能用。
0 Comments
張貼留言