#include<algorithm>
using namespace std;
template <class T>
class element
{
public:
element() { key = T(0);}
~element() {};
public:
T key;
};
class insert_sort
{
public:
template <class T>
void Sort(element<T> list[], int n);
public:
insert_sort(void);
~insert_sort(void);
};
template <class T>
void insert_sort::Sort(element<T> list[], int n)
{
int i = 0, j = 0;
element<T> next;
for(i = 1; i < n; i++)
{
next = list[i];
for(j = i-1; j >=0 && next.key < list[j].key; j--)
{
list[j+1] = list[j];
}
list[j+1] = next;
}
}
排序算法之插入排序(模板类)
最新推荐文章于 2023-12-25 19:47:39 发布