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

📄 dictionary.h

📁 该压缩文件夹内有诸多常用算法和数据结构的c++模板编程实现
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -