Problem1676--插入排序(课程G)

1676: 插入排序(课程G)

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

完善程序:
输入N个整数,使用插入排序法从小到大输出。

#include<bits/stdc++.h>
using namespace std;
int N;
int a[100010];
int main()
{
    freopen("1456.in","r",stdin);
    freopen("1456.out","w",stdout);
     cin >> N;
     for (int i=1; i <= N; i++) //输入数组
		cin >> a[i];
    a[0]= -10000001;      //添加一个“哨兵”
     for (int i=1; i ____ N ; i++)  //新数位置
	 {
           int temp=a[i];      //取当前的新数---(A)
		int j;
		for (j=i-1; a[j] > temp; j--) //找到适当位置。---(B)
		   ________;	    	  //---(C)	
	  a[____]=temp;              
     }
	 
	 for (int i=1; i &lt= N; i++)
		cout << a[i] << " ";
    return 0;
}



Input

第一行1个正整数:N,范围在[1,1000]。
第二行N个整数,每个整数范围在[0,1000000]。

Output

一行N个从小到大的整数。

Sample Input Copy

4 
5 3 6 1

Sample Output Copy

1 3 5 6

Source/Category