你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

7-5 简化的插入排序 (15 分)

2021/11/24 23:10:22
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
using namespace std; 
int main(){
	int n,a[10],i=0;
	cin>>n;
	while(i<n){
		cin>>a[i];
		i++;
	}
	cin>>a[n];
	sort(a,a+i+1);
	for(int j=0;j<n+1;j++){
		cout<<a[j]<<" ";
	}
	return 0;
}

答案如上

本题要求编写程序,将一个给定的整数插到原本有序的整数序列中,使结果序列仍然有序。

输入格式:

输入在第一行先给出非负整数N(<10);第二行给出N个从小到大排好顺序的整数;第三行给出一个整数X。

输出格式:

在一行内输出将X插入后仍然从小到大有序的整数序列,每个数字后面有一个空格。

输入样例:

5
1 2 4 5 7
3

结尾无空行

输出样例:

1 2 3 4 5 7 

结尾无空行