【四种排序】目录
1.直接插入排序
2.希尔排序
3.快速排序
4.选择排序
1.直接插入排序
#includeusing namespace std; const int MAX=1e+6; typedef long long ll; ll a[MAX]; void scnf(int st,int n) { for(int i=1; i<=n; i++)cin>>a[i]; } void print(int st,int n) { for(int i=st; i<=n; i++)cout<>n; scnf(1,n); for(int i=2; i<=n; i++) { if(a[i]
2.希尔排序
#includeusing namespace std; const int MAX=1e+6; typedef long long ll; ll a[MAX],d[]= {1,2,5,7}; void scnf(int st,int n) { for(int i=1; i<=n; i++)cin>>a[i]; } void print(int st,int n) { for(int i=st; i<=n; i++)cout<>n; scnf(1,n); for(int i=3; i>=0; i--) { for(int j=d[i]+1; j<=n; j++) { a[0]=a[j]; int k; for( k=j-d[i];k>0&&a[0]
3.快速排序
#includeusing namespace std; const int MAX=1e+6; typedef long long ll; ll a[MAX],d[]= {1,2,5,7}; void scnf(int st,int n) { for(int i=1; i<=n; i++)cin>>a[i]; } void print(int st,int n) { for(int i=st; i<=n; i++)cout >n; scnf(1,n); qsort(1,n); print(1,n); }
4.选择排序
#includeusing namespace std; const int MAX=1e+6; typedef long long ll; ll a[MAX],d[]= {1,2,5,7}; void scnf(int st,int n) { for(int i=1; i<=n; i++)cin>>a[i]; } void print(int st,int n) { for(int i=st; i<=n; i++)cout<>n; scnf(1,n); sesort(n); print(1,n); }



