直接插入排序(稳定)

来源:互联网 发布:办公软件系统 编辑:程序博客网 时间:2024/05/17 06:45
template<class T>
void InsertSort(T a[],int n)
{
 T temp;
 for(int i=1;i<n;i++)
 {
  for(int j=i;j>0&&a[j]<a[j-1];j--)
  {
   temp=a[j-1];
   a[j-1]=a[j];
   a[j]=temp; 
  }
 }
}
原创粉丝点击