插入排序算法
#ifndef INSERT_SORT_H
#define INSERT_SORT_H
#include<assert.h>
template<class T,int n>
void swap(T* s,int i,int j)
{
assert((i<n)&&(j<n));
T temp=s[i];
s[i]=s[j];
s[j]=temp;
}
template<class T,int n>
void insert_sort(T* s)
{
int i=1,j;
for(i=1;i<n;i++)
for(j=i;j>0;j--)
{
if(s[j]<s[j-1])
swap<T,n>(s,j,j-1);
}
}
#endif


浙公网安备 33010602011771号