//希尔排序 #include <iostream> using namespace std; int main(){ int a[10] = {2,5,9,6,4,3,5,10,7,6}; int h = 9; while(h>=1) { for(int i = h;i<10;i++) { int pre = i-h; int cur = a[i]; while(pre>=0 && cur<a[pre]) { a[pre+h] = a[pre]; pre-=h; } a[pre+h] = cur; } h = h/3; } for(int i = 0;i<10;i++) { cout<<a[i]<<‘ ‘; } }
原文:https://www.cnblogs.com/kkkk5/p/12622761.html