Merge branch 'master' of http://www.hyzgame.com:3000/hyzboy/CMUtil
This commit is contained in:
commit
f3f6fcef88
@ -2,10 +2,9 @@
|
|||||||
#define HGL_ALGORITHM_SORT_INCLUDE
|
#define HGL_ALGORITHM_SORT_INCLUDE
|
||||||
|
|
||||||
#include<hgl/CompOperator.h>
|
#include<hgl/CompOperator.h>
|
||||||
|
#include<hgl/type/List.h>
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
|
|
||||||
namespace hgl
|
|
||||||
{
|
|
||||||
template<typename T> class SortBase
|
template<typename T> class SortBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@ -133,7 +132,7 @@ namespace hgl
|
|||||||
};//class HeapSort:public SortBase<T>
|
};//class HeapSort:public SortBase<T>
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Sort(T *data,int count,Comparator<T> *comp=new Comparator<T>())
|
bool Sort(T *data,int count,Comparator<T> *comp)
|
||||||
{
|
{
|
||||||
HeapSort<T> hs(data,count,comp);
|
HeapSort<T> hs(data,count,comp);
|
||||||
|
|
||||||
@ -141,12 +140,32 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool Sort(DataArray<T> &list,Comparator<T> *comp=Comparator<T>())
|
bool Sort(T *data,int count)
|
||||||
|
{
|
||||||
|
Comparator<T> rnc;
|
||||||
|
|
||||||
|
HeapSort<T> hs(data,count,&rnc);
|
||||||
|
|
||||||
|
return hs.sort();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool Sort(hgl::DataArray<T> &list,Comparator<T> *comp)
|
||||||
{
|
{
|
||||||
return Sort(list.GetData(),
|
return Sort(list.GetData(),
|
||||||
list.GetCount(),
|
list.GetCount(),
|
||||||
comp);
|
comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool Sort(hgl::DataArray<T> &list)
|
||||||
|
{
|
||||||
|
Comparator<T> rnc;
|
||||||
|
|
||||||
|
return Sort<T>(list,&rnc);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//仅实现模拟虚拟成员函数即可,无需整个类重载
|
//仅实现模拟虚拟成员函数即可,无需整个类重载
|
||||||
template<> int Comparator<BagCell>::compare(const BagCell &it1,const BagCell &it2) const
|
template<> int Comparator<BagCell>::compare(const BagCell &it1,const BagCell &it2) const
|
||||||
@ -168,5 +187,4 @@ namespace hgl
|
|||||||
hgl::Sort<BagCell>(cell_list,BAG_SLOT_COUNT,&comp_baginfo);
|
hgl::Sort<BagCell>(cell_list,BAG_SLOT_COUNT,&comp_baginfo);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}//namespace hgl
|
|
||||||
#endif//HGL_ALGORITHM_SORT_INCLUDE
|
#endif//HGL_ALGORITHM_SORT_INCLUDE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user