Topic Portal
1 /*2 Insert sort--poker sort3 Verify the correctness of the algorithm with the zstu3539 problem4 */5#include <cstdio>6#include <iostream>7#include <algorithm>8#include <ctime>9#include <cstdlib>Ten using namespacestd; One A Const intMAXN =1000000+Ten; - Const intINF =0x3f3f3f3f; - intA[MAXN]; the - voidInsertsort (int*a,intN) - { - for(intI=2; i<=n; ++i) + { - if(a[i-1] >A[i]) + { A intx =A[i]; at intj = i-1; - while(J >0&& A[j] >x) - { -a[j+1] =A[j]; ---J; - } ina[j+1] =x; - } to } + } - the * intMainvoid) $ {Panax Notoginseng //freopen ("rand_small.in", "R", stdin); - intN; the + while(SCANF ("%d", &n)! =EOF) A { the if(n = =0) + Continue; - for(intI=1; i<=n; ++i) $ { $scanf ("%d", &a[i]); - } - the Insertsort (A, n); - Wuyi BOOLFlag =true; the for(intI=1; i<=n; ++i) - { Wu if(flag) - { Aboutprintf ("%d", A[i]); $Flag =false; - } - Else -printf ("%d", A[i]); A } +Puts (""); the } - $ return 0; the}
Sort algorithm Insertion sort