⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortbench.h

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 H
字号:
#ifndef _SORTWRAPPER_H
#define _SORTWRAPPER_H

template <class Type>
class SortWrapper
{
  public:
    SortWrapper()
    { }
    SortWrapper(const Type& t)
      : myValue(t)
    { }
    SortWrapper(const SortWrapper& sw)
      : myValue(sw.myValue)
    {
        ourCopies++;
    }
    const SortWrapper& operator = (const SortWrapper& sw)
    {
        ourAssigns++;
        myValue = sw.myValue;
        return *this;
    }
    bool less(const SortWrapper<Type>& rhs) const
    {
        ourCompares++;
        return myValue < rhs.myValue;
    }
    bool equal(const SortWrapper<Type>& rhs) const
    {
        ourCompares++;
        return myValue == rhs.myValue;    
    }
    const Type& value() const
    {
        return myValue;
    }
    static unsigned long compareCount()  { return ourCompares;}
    static unsigned long assignCount()   { return ourAssigns;}
    static unsigned long copyCount()     { return ourCopies;}
    static void clear()
    {
        ourCompares = ourCopies = ourAssigns = 0;
    }
    
  private:
    Type myValue;
    static unsigned long ourCompares;
    static unsigned long ourCopies;
    static unsigned long ourAssigns;
};

template <class Type>
unsigned long SortWrapper<Type>::ourCompares = 0;

template <class Type>
unsigned long SortWrapper<Type>::ourAssigns = 0;

template <class Type>
unsigned long SortWrapper<Type>::ourCopies = 0;

template <class Type>
bool operator < (const SortWrapper<Type>& lhs,
                 const SortWrapper<Type>& rhs)
{
    return lhs.less(rhs);
} 

template <class Type>
bool operator == (const SortWrapper<Type>& lhs,
                 const SortWrapper<Type>& rhs)
{
    return lhs.equal(rhs);
}

template <class Type>
bool operator <= (const SortWrapper<Type>& lhs,
                  const SortWrapper<Type>& rhs)
{
    return lhs < rhs || lhs == rhs;
}




template <class Type>
ostream& operator << (ostream& os, const SortWrapper<Type>& sw)
{
    os << sw.value();
    return os;
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -