//堆排序#include#include int a[100010],len=0;void insert(int x){ a[++len]=x; int k=len,t; while(k>1 && a[k] a[2*k] && 2*k<=len)|| (a[k]>a[2*k+1] && 2*k+1<=len)){ m=2*k; if(a[m]>a[m+1] && m+1<=len)m++; t=a[k];a[k]=a[m];a[m]=t; k=m; } for(j=1;j<=len;j++)printf("%d ",a[j]); puts(""); } system("pause"); return 0;}//快速排序#include #include int a[10000];void qsort(int x,int y){ int u,v,m,t; m=a[(x+y)/2]; u=x;v=y; while(u m)v--; if(u<=v){ t=a[u];a[u]=a[v];a[v]=t; u++;v--; } } if(x #include int a[10000];void gbpx(int x,int y){ int u,v,m,i; int t[10000]; if(x==y)return; m=(x+y)/2; if(x<=m)gbpx(x,m); if(m+1<=y)gbpx(m+1,y); u=x;v=m+1; int k=0; while(u<=m && v<=y){ if(a[u] #include int a[1000000+10];int main(){ int i,j,k,m,n,max=0; scanf("%d%d",&n,&k); for(i=1;i<=n;i++) scanf("%d",&a[i]); int l=1,r=n; while(l<=r){ m=(l+r)/2; if(a[m]==k){ printf("%d",m); break; }else if(a[m] k) r=m-1; } if(l>r)printf("-1\n"); system("pause"); return 0;}//统计排序#include #include int a[1000000+10];int main(){ int i,j,k,m,n,max=0; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&k); a[k]++; max=k>max?k:max; } for(i=0;i<=max;i++){ for(j=1;j<=a[i];j++) printf("%d ",i); } system("pause"); return 0;}//冒泡排序#include #include int a[10000];int main(){ int i,j,k,m,n; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=n-1;i>=1;i--) for(j=1;j<=i;j++) if(a[j]>a[j+1]){ k=a[j];a[j]=a[j+1];a[j+1]=k; } for(i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' '); system("pause"); return 0;}//选择排序#include #include int a[10000];int main(){ int i,j,k,m,n; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i a[j]){ k=a[i];a[i]=a[j];a[j]=k; } for(i=1;i<=n;i++) printf("%d%c",a[i],i==n?'\n':' '); system("pause"); return 0;}