标签:pre scanf ios scan namespace shellSort iostream space \n
#include<iostream> #include<stdio.h> using namespace std; void shellsort(int a[],int n){ int i,j; int jump=n; do{ jump=jump/3+1;//浮动 for (i=jump+1;i<=n;i++){ if (a[i]<a[i-jump]) { a[0]=a[i]; for(j=i-jump;j>0 && a[0]<a[j];j-=jump) { a[j+jump]=a[j];//找的需要交换的位置 } a[j+jump]=a[0];//进行交换 } } }while(jump>1); } int main(){ int a[100]; int n; scanf("%d",&n); for (int i=1;i<=n;i++){ scanf("%d",&a[i]); } shellsort(a,n); for (int i=1;i<=n;i++){ printf("%d\n",a[i]); } return 0; }
标签:pre scanf ios scan namespace shellSort iostream space \n
原文地址:https://www.cnblogs.com/bluefly-hrbust/p/10182697.html