-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellSort.cpp
More file actions
42 lines (40 loc) · 1.06 KB
/
ShellSort.cpp
File metadata and controls
42 lines (40 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*************************************************************************
> File Name: ShellSort.cpp
> Author: sukingw
> Mail: [email protected]
> Created Time: Sun 27 Aug 2017 08:07:10 PM CST
************************************************************************/
// 本程序是希尔排序算法练习
#include<iostream>
#include<vector>
using namespace std;
void ShellSort(vector<int> &a){
int i,j;
int temp;
int pathlong = a.size();
do{
pathlong = pathlong/3+1;
for(i=pathlong; i<a.size();i += pathlong){
if(a[i] < a[i-pathlong]){
temp = a[i];
for(j = i; j-pathlong >= 0 && a[j-pathlong]>temp; j -= pathlong){
a[j] = a[j-pathlong];
}
a[j] = temp;
}
}
}while(pathlong >1);
}
int main(){
int a;
vector<int> input;
while(cin>>a){
input.push_back(a);
}
ShellSort(input);
for(auto it = input.begin();it != input.end();++it){
cout<<*it<< " ";
}
cout<<endl;
return 0;
}