Zadanie domowe #3
Treść zadania
#include <vector>
template<typename Key>
struct Node {
Key key;
// ...
};
template<typename Key>
class Tree {
public:
// ...
virtual void erase(const Key& key) { /* ... */ }
virtual Node<Key>* insert(const Key& key) { /* ... */ }
virtual Node<Key>* find(const Key& key) const { /* ... */ }
};
template<typename Key>
class BinarySearchTree : public Tree<Key> {
// ...
};
template<typename Key>
class SplayTree : public Tree<Key> {
// ...
};
template<typename Key>
class AVLTree : public Tree<Key> {
// ...
};
// ...
auto bst = BinarySearchTree<int>();
auto splay = SplayTree<int>();
auto avl = AVLTree<int>();
std::vector<Tree<int>*> trees{};
trees.push_back(&bst);
trees.push_back(&splay);
trees.push_back(&avl);
// Operacje wykonujemy dla każdego typu drzewa
for (const auto& tree : trees) {
tree->insert(51); // ...-00.pdf
tree->insert(22); // ...-01.pdf
tree->insert(43); // ...-02.pdf
tree->insert(84); // ...-03.pdf
tree->insert(35); // ...-04.pdf
tree->insert(86); // ...-05.pdf
tree->insert(57); // ...-06.pdf
tree->insert(98); // ...-07.pdf
tree->find(57); // ...-08.pdf
tree->erase(57); // ...-09.pdf
tree->erase(51); // ...-10.pdf
}
// ...Przykład zapisu drzewa w języku DOT (Graphviz)


Przykład generowania szkicu drzewa za pomocą TikZ/LaTeX

Pomocne narzędzia
Forma dostarczenia wyników
Last updated