dictionary.h
来自「该压缩文件夹内有诸多常用算法和数据结构的c++模板编程实现」· C头文件 代码 · 共 56 行
H
56 行
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include "LinkedList.h"
template<class K,class V>
class Dictionary
{
public:
bool put(K key,V value)
{
if (keys.find(key)==-1)
{
keys.add(key);
values.add(value);
return true;
}
return false;
}
V get(K key)
{
int index=keys.find(key);
if (index==-1)
{
return NULL;
}
return values.get(index);
}
void clear()
{
keys.clear();
values.clear();
}
int size()
{
return keys.size();
}
LinkedList<K> getKeys()
{
return keys;
}
bool remove(K key)
{
int index=keys.find(key);
if (index==-1)
{
return false;
}
keys.remove(index);
values.remove(index);
return true;
}
protected:
LinkedList<K> keys;
LinkedList<V> values;
private:
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?