Insertion_Sort(插入排序)

#include "stdafx.h"
#include <iostream>
using namespace std;

void _tmain(int argc, _TCHAR* argv[])
{    
    int temp[10];    
    for(int i=0;i<10;i++)
    {
        cin>>temp[i];
        int k=i;
        int key=temp[k];
        while(k>0&&temp[k-1]<key)
        {
            temp[k]=temp[k-1];
            temp[k-1]=key;
            k--;            
        }    
    }
    for(int s=0;s<10;s++)
    {
        cout<<temp[s]<<" ";
    }
    cout<<endl;
    int s;
    cin>>s;
}
原文地址:https://www.cnblogs.com/super86/p/3038581.html