#include<iostream>
using namespace std;
void InsertSort( int* array, int n )
{
int j, temp;
for( int i = 1; i < n; i++ )
{
temp = array[i];
j =i - 1;
while( array[j] > temp && j >= 0)
{
array[j+1] = array[j];
j--;
}
array[j+1] = temp;
}
}
void OutPut( int* array, int n )
{
for( int i = 0; i < n; i++ )
{
cout<<array[i]<<" ";
}
cout<<endl;
}
int main()
{
const int N = 10;
int a[N] = {13,2,4,16,336,3,8,9,10,11};
OutPut( a, N);
InsertSort( a, N);
OutPut( a, N);
return 0;
}
转载于:https://blog.51cto.com/8734514/1625991