标签:
#include <iostream>using namespace std;int main(){const int MAXN = 100;int a[MAXN];int n;cin >> n;int i, j;int low, high, mid;for(i = 1; i <= n; i++){cin >> a[i];}int tmp;for(i = 2; i <= n; i++){tmp = a[i];low = 1;high = i-1;while(low <= high){mid = (low + high) / 2;if(a[mid] < a[i])low = mid + 1;elsehigh = mid - 1;}for(j = i-1; j >= low; j--)a[j+1] = a[j];a[low] = tmp;}for(i = 1; i <= n; i++)cout << a[i] << " ";return 0;}
标签:
原文地址:http://www.cnblogs.com/z-dianjun/p/5907106.html