1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#ifndef _SORTING_H_
#define _SORTING_H_
#include <iostream>
#include <cstring>
using namespace std;
template <class Elem, class Comp>
class Sortings
{
public:
static void merge(Elem *arr, unsigned int n);
// static void quick(Elem *arr, unsigned int n); do merge or this one
static void select(Elem *arr, unsigned int n);
static void shell(Elem *arr, unsigned int n);
static void radix(Elem *arr, unsigned int n); // when using radix, Comp should be a class
// with a static method "uintVal(...)" that gives an unsigned int representation of the item
private:
// These are all optional, add or remove as functions as you need
static const unsigned int THRESHOLD = 3; // used by shell
static const unsigned int RADIX = 16; // used by radix
static void insert2(Elem *arr, unsigned int incr, unsigned int n);
static void swap(Elem *arr, unsigned int, unsigned int);
static void mergeRecurse(Elem *arr, Elem tmp[], unsigned int l, unsigned int r);
};
class intuival
{
public:
static unsigned int uintVal(int n);
};
class intintCompare
{
public:
static bool lt(int, int);
static bool gt(int, int);
static bool eq(int, int);
};
class strstrCompare
{
public:
static bool lt(char*, char*);
static bool gt(char*, char*);
static bool eq(char*, char*);
};
#endif
|