<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                M為除留余數法的模數, ht是指向動態生成的一維數組指針, empty是標志數組的指針. 成員函數Find()在散列表中搜索與x關鍵字相同的元素. 若表中存在與x關鍵字值相同的元素, 則將其復制給x, pos指示該位置, 函數返回Success. 若表已滿, 函數返回Overflow. 若表未滿, 函數返回NotPresent, pos指示首次遇到的空值位置. 實現代碼: ~~~ #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" #include "queue" #include "stack" #include "cmath" #include "utility" #include "map" #include "set" #include "vector" #include "list" using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const int NeverUsed = -100; enum ResultCode { Underflow, Overflow, Success, Duplicate, NotPresent }; template <class T> class DynamicSet { public: virtual ResultCode Search(T &x) = 0; virtual ResultCode Insert(T &x) = 0; virtual ResultCode Remove(T &x) = 0; /* data */ }; template <class T> class HashTable: public DynamicSet<T> { public: HashTable(int divisor = 11); ~HashTable() { delete []ht; delete []empty; } ResultCode Search(T &x); ResultCode Insert(T &x); ResultCode Remove(T &x); void Output(); /* data */ private: ResultCode Find(T &x, int &pos); T h(T x); int M; T *ht; bool *empty; }; template <class T> void HashTable<T>::Output() { for(int i = 0; i < M; ++i) cout << i << ' '; cout << endl; for(int i = 0; i < M; ++i) if(ht[i] == NeverUsed) cout << "NU" << ' '; else cout << ht[i] << ' '; cout << endl; for(int i = 0; i < M; ++i) if(empty[i]) cout << "T " << ' '; else cout << "F " << ' '; cout << endl; } template <class T> T HashTable<T>::h(T x) { return x % 11; } template <class T> HashTable<T>::HashTable(int divisor) { M = divisor; ht = new T[M]; empty = new bool[M]; for(int i = 0; i < M; ++i) empty[i] = true; for(int i = 0; i < M; ++i) ht[i] = NeverUsed; } template <class T> ResultCode HashTable<T>::Find(T &x, int &pos) { pos = h(x); // h為散列函數, h(x) < M int i = pos, j = -1; do{ if(ht[pos] == NeverUsed && j == -1) j = pos; // 記錄首次遇到空值的位置 if(empty[pos]) break; // 表中沒有與x有相同關鍵字的元素 if(ht[pos] == x) { // ht[pos]的關鍵字與值與x的關鍵字值相同 x = ht[pos]; return Success; // 搜索成功, ht[pos]賦值給x } pos = (pos + 1) % M; }while(pos != i); // 已搜索完整個散列表 if(j == -1) return Overflow; // 表已滿 pos = j; // 記錄首次遇到的空值位置 return NotPresent; } template <class T> ResultCode HashTable<T>::Search(T &x) { int pos; if(Find(x, pos) == Success) return Success; return NotPresent; } template <class T> ResultCode HashTable<T>::Insert(T &x) { int pos; ResultCode reslt = Find(x, pos); if(reslt == NotPresent) { ht[pos] = x; empty[pos] = false; return Success; } if(reslt == Success) return Duplicate; return Overflow; } template <class T> ResultCode HashTable<T>::Remove(T &x) { int pos; if(Find(x, pos) == Success) { ht[pos] = NeverUsed; return Success; } return NotPresent; } int main(int argc, char const *argv[]) { HashTable<int> ht; int x = 80; ht.Insert(x); ht.Output(); x = 80; ht.Insert(x); ht.Output(); x = 40; ht.Insert(x); ht.Output(); x = 65; ht.Insert(x); ht.Output(); x = 28; ht.Insert(x); ht.Output(); x = 24; ht.Insert(x); ht.Output(); x = 35; ht.Insert(x); ht.Output(); x = 58; ht.Insert(x); ht.Output(); return 0; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看