ulldict.h

来自「数据结构与算法分析」· C头文件 代码 · 共 37 行

H
37
字号
#include "dictionary.h"

// Dictionary implemented with an unsorted linked list
template <class Key, class Elem, class KEComp, class EEComp>
class ULLdict : public Dictionary<Key, Elem, KEComp, EEComp> {
private:
  LList<Elem>* list;
public:
  ULLdict(int size=DefaultListSize)
    { list = new LList<Elem>(size); }
  ~ULLdict() { delete list; }
  void clear() { list->clear(); }
  bool insert(const Elem& e)
    { return list->append(e); }
  bool remove(const Key& K, Elem& e) {
    for(list->setStart(); list->getValue(e); list->next())
      if (KEComp::eq(K, e)) {
        list->remove(e);
        return true;
      }
    return false;
  }
  bool removeAny(Elem& e) {
    if (size() == 0) return false;
    list->setStart();
    list->remove(e);
    return true;
  }
  bool find(const Key& K, Elem& e) const {
    for(list->setStart(); list->getValue(e); list->next())
      if (KEComp::eq(K, e)) return true;
    return false;
  }
  int size()
    { return list->leftLength() + list->rightLength(); }
};

⌨️ 快捷键说明

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