数据结构—插入排序

#include

 

using namespace std;

 

void InsertionSort(int* a,int n);

 

int main()

{

    int x[]={2,4,6,8,0,1,3,5,7,9};

    InsertionSort(x,10);

    for(int i=0;i<10;i++)

        cout<<x[i]<<endl;

    return 0;

}

 

 

void InsertionSort(int* a,int n)

{

    int in,out;

    int temp;

    for(out=1;out

    {

        temp=a[out];

        in=out;

        while(in>0 && a[in-1]>temp)

        {

            a[in]=a[in-1];

            in--;

        }

        a[in]=temp;

       

}

 

 

运行结果:

 

数据结构—插入排序

posted @ 2016-04-14 18:14  硫酸亚铜  阅读(187)  评论(0编辑  收藏  举报