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

📄 ualdict.h

📁 数据结构与算法分析(C++)(版第二版)源码
💻 H
字号:
#include "dictionary.h"

// Dictionary implemented with an unsorted array-based list
template <class Key, class Elem, class KEComp, class EEComp>
class UALdict : public Dictionary<Key,Elem,KEComp,EEComp> {
private:
  AList<Elem>* list;
public:
  UALdict(int size=DefaultListSize)
    { list = new AList<Elem>(size); }
  ~UALdict() { 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->setEnd();
    list->prev();
    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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -