From 3afa4e27e9cf444c4d6c875d41ab4a25d7454980 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Fri, 28 Jul 2023 20:40:54 +0800 Subject: [PATCH] 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