ch.h

来自「一本全面剖析C++数据结构算法的书籍」· C头文件 代码 · 共 45 行

H
45
字号
// file Chash.h#ifndef ChainedHashTable_#define ChainedHashTable_#include "sochain.h" // sorted chain#include <iostream.h>template<class etype, class ktype>class ChainHashTable {   public:      ChainHashTable(int divisor = 11); // constructor      ~ChainHashTable() {delete [] ht;}      int Search(ktype k, etype& e)          {e.key = k; return ht[k % D].Search(e);}      int Insert(etype e)          {return ht[e.key % D].DistinctInsert(e);}      int Delete(ktype k, etype& e)          {e.key = k; return ht[k % D].Delete(e);}      void Print();   private:      int D;      SortedChain<etype> *ht;};template<class etype, class ktype>ChainHashTable<etype, ktype>::ChainHashTable(int divisor){   D = divisor;   ht = new SortedChain<etype> [D];   if (!ht)    {cerr << "Out of memory" << endl;     exit(1);}}template<class etype, class ktype>void ChainHashTable<etype, ktype>::Print(){   for (int i = 0; i < D; i++) {     cout << "Chain " << i << ' ';     ht[i].Print();}}#endif

⌨️ 快捷键说明

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