


【算法代码】
- #include
- using namespace std;
-
- int shellSort(vector<int> &a) {
- int t,id;
- int step=a.size()/2;
- while(step) {
- for(int i=step; i
size(); i++) { - t=a[i];
- id=i-step;
- a[id+step]=a[id];
- id=id-step;
- }
- a[id+step]=t;
- }
- step=step/2;
- }
- }
-
- int main() {
- vector<int> v;
- int n;
- cin>>n;
- for(int i=1; i<=n; i++) {
- int x;
- cin>>x;
- v.push_back(x);
- }
- shellSort(v);
-
- for(int i=0; i
size(); i++) { - cout<
" "; - }
-
- return 0;
- }
-
-
- /*
- in:
- 8
- 49 38 65 97 76 13 27 49
- out:
- 13 27 38 49 49 65 76 97
- */