From 14c419d145d509a63e22ecf48ffd42b5a504a84f Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Fri, 28 Jul 2023 20:13:19 +0800 Subject: [PATCH 1/2] fixed include --- inc/hgl/util/sort/Sort.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inc/hgl/util/sort/Sort.h b/inc/hgl/util/sort/Sort.h index a2d7e29..099c5e8 100644 --- a/inc/hgl/util/sort/Sort.h +++ b/inc/hgl/util/sort/Sort.h @@ -2,6 +2,8 @@ #define HGL_ALGORITHM_SORT_INCLUDE #include +#include +#include #include template class SortBase @@ -68,8 +70,6 @@ public: virtual bool sort()=0; //排序 };//struct SortBase -namespace hgl -{ //堆排序 template class HeapSort:public SortBase { @@ -141,7 +141,7 @@ namespace hgl } template - bool Sort(List &list,Comparator *comp=Comparator()) + bool Sort(hgl::List &list,Comparator *comp=Comparator()) { return Sort(list.GetData(), list.GetCount(), @@ -169,5 +169,4 @@ namespace hgl hgl::Sort(cell_list,BAG_SLOT_COUNT,&comp_baginfo); } */ -}//namespace hgl #endif//HGL_ALGORITHM_SORT_INCLUDE From 3afa4e27e9cf444c4d6c875d41ab4a25d7454980 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Fri, 28 Jul 2023 20:40:54 +0800 Subject: [PATCH 2/2] improved Sort.h --- inc/hgl/util/sort/Sort.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/inc/hgl/util/sort/Sort.h b/inc/hgl/util/sort/Sort.h index f749f12..f423ae5 100644 --- a/inc/hgl/util/sort/Sort.h +++ b/inc/hgl/util/sort/Sort.h @@ -132,7 +132,7 @@ public: };//class HeapSort:public SortBase template -bool Sort(T *data,int count,Comparator *comp=new Comparator()) +bool Sort(T *data,int count,Comparator *comp) { HeapSort hs(data,count,comp); @@ -140,12 +140,32 @@ bool Sort(T *data,int count,Comparator *comp=new Comparator()) } template -bool Sort(hgl::DataArray &list,Comparator *comp=Comparator()) +bool Sort(T *data,int count) +{ + Comparator rnc; + + HeapSort hs(data,count,&rnc); + + return hs.sort(); +} + + +template +bool Sort(hgl::DataArray &list,Comparator *comp) { return Sort(list.GetData(), list.GetCount(), comp); } + +template +bool Sort(hgl::DataArray &list) +{ + Comparator rnc; + + return Sort(list,&rnc); +} + /* //仅实现模拟虚拟成员函数即可,无需整个类重载 template<> int Comparator::compare(const BagCell &it1,const BagCell &it2) const