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

📄 book.h

📁 数据结构与算法分析(C++)(版第二版)源码
💻 H
字号:
#include <time.h>  // Used by timing functions

// Utility functions and macros

// Return true iff x is even
inline bool EVEN(int x) { return (x % 2) == 0; }

// Return true iff x is odd
inline bool ODD(int x) { return (x & 1) != 0; }

const int DefaultListSize = 10; // Lists, etc. default size 

// Assert: If boolean expression is false, print a message
//   and terminate the program
void Assert(bool val, char* string) {
  if (!val) { // Assertion failed -- close the program
    cout << "Assertion Failed: " << string << endl;
    exit(-1);
  }
}

// Random number generator functions

inline void Randomize() // Seed the generator
  { srand(1); }

// Return a random value in range 0 to n-1
inline int Random(int n)
  { return rand() % (n); }

// Swap two elements in a generic array
template<class Elem>
inline void swap(Elem A[], int i, int j) {
  Elem temp = A[i];
  A[i] = A[j];
  A[j] = temp;
}

// Swap two objects passed by reference
template<class Elem>
inline void swap(Elem &e1, Elem &e2) {
  Elem temp = e1;
  e1 = e2;
  e2 = temp;
}

// Timing variables and functions
clock_t tstart = 0;  // Time at beginning of timed section

// Initialize the program timer
void Settime()
  { tstart = clock(); }

// Return the elapsed time since the last call to Settime
double Gettime()
  { return (double)((double)clock() - (double)tstart)/
           (double)CLOCKS_PER_SEC; }

// Your basic int type as an object.
class Int {
private:
  int val;
public:
  Int(int input=0) { val = input; }
  // The following is for those times when we actually
  //   need to get a value, rather than compare objects.
  int key() const { return val; }
  // Overload = to support Int foo = 5 syntax
  Int operator= (int input) { val = input; }
};

// Let us print out Ints easily
ostream& operator<<(ostream& s, const Int& i)
  { return s << i.key(); }
ostream& operator<<(ostream& s, const Int* i)
  { return s << i->key(); }

⌨️ 快捷键说明

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