低级排序
- 冒泡排序(低级排序中速度最慢)
- 选择排序
- 插入排序(低级排序算法中最快的)
#include<iostream>
using namespace std;
template<class T>
void InsertionSort(T *a,int n);
void main()
{
double x[] = {2.5,4,6.6,8.8,0,1.5,3,5,7,9};
InsertionSort(x,10);
for(int i=0;i<10;i++)
cout<<x[i]<<endl;
// return 0;
}
template<class T>
void InsertionSort(T *a,int n)
{
int in,out;
for(out=1;out<n;++out)
{
int temp= a[out];
in = out;
while(in>0 && a[in-1]>=temp)
{
a[in] = a[in-1];
--in;
}
a[in] = temp;
}
}