/* * tree_dictionary.cpp * * Created on: 09.01.2013 * Author: trifon */ #include "AVLtree.cpp" #include "dictionary.h" template class TreeDictionary : public Dictionary { private: AVLTree d; public: bool add(K const& key, V const& value) { return d.insert(key, value); } V* search(K const& key) const { return d.search(key); } bool remove(K const& key) { return d.remove(key); } void print() const { d.print(); } private: void collectKeys(BinTreeIterator > it, LinkedList& keys) const { if (it) { collectKeys(++it, keys); keys.toEnd((*it).key); collectKeys(it++, keys); } } void collectValues(BinTreeIterator > it, LinkedList& values) const { if (it) { collectValues(++it, values); values.toEnd((*it).value); collectValues(it++, values); } } public: LinkedList keys() const { LinkedList k; collectKeys(d.iterator(), k); return k; } LinkedList values() const { LinkedList v; collectValues(d.iterator(), v); return v; } };