#include<stdio.h>int main (){int a[100], i, j, t, n, k;scanf("%d",&n);for( i =0; i < n; i++){scanf("%d",&a[i]);}
k = n/2;while( k >0){for( i = k; i < n; i++){
t = a[i];for( j = i-k; j >=0&& a[j]> t; j-=k ){
a[j+k]= a[j];}
a[j+k]= t;}
k = k/2;}for( i =0; i < n; i++){printf("%d ", a[i]);}return0;}
堆排序(最小堆性质)#include<stdio.h>int h[101];int n;void swap (int x,int y ){int t;
t = h[x];
h[x]= h[y];
h[y]= t;return;}void siftDown (int i ){int t, flag =0;while( i*2<= n ){if( h[i]> h[i*2])
t = i*2;else
t = i;if( i*2<= n ){if( h[t]> h[i*2+1])
t = i*2+1;}if( t != i ){swap(t, i);
i = t;}else
flag =1;}return;}void creat (){int i;for( i = n/2; i >=1; i--){siftDown(i);}return;}int deletemax (){int t;
t = h[1];
h[1]= h[n];
n--;siftDown(1);return t;}int main (){int i, num;scanf("%d",&num);for( i =1; i <= num; i++)scanf("%d",&h[i]);
n = num;creat();for( i =1; i <= num; i++)printf("%d",deletemax());getchar();getchar();return0;}
快序排序寻找第k小的数:快速排序每次都可以找到选择的基准数在排序完成的序列中的位置,那么如何寻找排序完成的序列中第k小的数呐?这是蓝桥杯第第八届的一道题目。#include <stdio.h>int quick_select(int a[], int l, int r, int k) { int p = rand() % (r - l + 1) + l; int...