直接插入排序

```
#include <iostream>

using namespace std;

const int N = 10;
int data[] ={6,1,2,7,9,3,4,5,10,8};
void directInsertSort(int* data,int n);
void printArray(int* data, int n);

int main()
{
    directInsertSort(data,N);
    printArray(data,N);
    return 0;
}



void directInsertSort(int* data,int n)
{
    int temp = 0;
    int i,j;
    for(i=1;i<n;++i)
    {
        temp = data[i];
        for(j=i-1;j>=0;--j)
        {
            if(temp>=data[j]) break;
            data[j+1] =data[j];
        }
        data[j+1] = temp;
    }
}
void printArray(int* data, int n)
{
    for(int i=0;i<n;++i)
    {
        cout<<data[i]<<" ";
    }
    cout<<endl;
}

```




原文地址:https://www.cnblogs.com/yldf/p/c7b46a65eae5be0d579e74fab8533922.html