implementation of stabilized quicksort

This commit is contained in:
2023-07-30 11:00:41 +02:00
parent ec42999812
commit a439e0be94
4 changed files with 92 additions and 10 deletions

View File

@@ -145,16 +145,30 @@ template<typename T, typename I, int type> struct LA_sort_traits;
template<typename T, typename I>
struct LA_sort_traits<T,I,0>
{
static inline bool compare(T object, I i, I j) {return object.bigger(i,j);};
static inline bool compare(const T &object, I i, I j) {return object.bigger(i,j);};
static inline bool comparestable(const T &object, I i, I j, I *auxkey)
{
bool r= object.bigger(i,j);
if(!r && object[i]==object[j]) r= auxkey[i]>auxkey[j];
return r;
};
};
template<typename T, typename I>
struct LA_sort_traits<T,I,1>
{
static inline bool compare(T object, I i, I j) {return object.smaller(i,j);};
static inline bool compare(const T &object, I i, I j) {return object.smaller(i,j);};
static inline bool comparestable(const T &object, I i, I j, I *auxkey)
{
bool r= object.smaller(i,j);
if(!r && object[i]==object[j]) r= auxkey[i]<auxkey[j];
return r;
};
};
//we will need to treat char and unsigned char as numbers in << and >> I/O operators
template<typename C>
struct LA_traits_io