#include<iostream>
#include<stdlib.h>
using namespace std;
#define maxSize 100
void InsertSort(int R[],int n)
{
int i,j;
int temp;
for(int i=1; i<n; i++)
{
temp=R[i];
j=i-1;
while(j>=0&&temp<R[j])
{
R[j+1]=R[j];
j--;
}
R[j+1]=temp;
}
}
int main()
{
int R[maxSize];
int n=10;
for(int i=0; i<n; i++)
R[i]=rand()%101;
cout<<"before sorting:"<<endl;
for(int i=0; i<n; i++)
cout<<R[i]<<"\t";
cout<<endl;
InsertSort(R,n);
cout<<"after sorting:"<<endl;
for(int i=0; i<n; i++)
cout<<R[i]<<"\t";
}
结果