zufeoj_插入排序

题目链接:http://acm.ocrosoft.com/problem.php?cid=1172&pid=4

题目描述

输入10个数,按照插入排序方法进行排序。

输入

输出

注意:输出最有一个数值后有个空格

2 4 6 6 7 9 9 10 10 25
25后面有一个空格

样例输入

4 6 7 2 6 9 10 25 9 10

样例输出

2 4 6 6 7 9 9 10 10 25


#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[11];
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    int i,j;
    for(i=1;i<10;i++){
        int temp=a[i];
        for(j=i-1;j>=0;j--){
            if(a[j]>temp){  
                a[j + 1] = a[j];  
            }
            else
            break;
        }
        a[j+1]=temp;
    }
    for(int i=0;i<10;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}






猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/80747091
今日推荐