算法导论<一>
插入排序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <queue> #include <set> #include <map> #include <cstring> #include <algorithm> using namespace std; const int mod = 1000000007; const int MM = 111111; int N; int num[MM]; void get_data() { int i,j,k; for(i=1;i<=N;i++) scanf("%d",&num[i]); } void Insertion_sort(int*A) { int i,j,k,key; for(i=2;i<=N;i++) { key=A[i]; j=i-1; while(j>0 && A[j]>key) { A[j+1]=A[j]; j--; } A[j+1]=key; } return; } void solve() { int i,j,k; Insertion_sort(num); for(i=1;i<=N;i++) printf("%d ",num[i]); printf("\n"); } int main() { while(scanf("%d",&N)!=EOF) get_data(),solve(); return 0; }