#include <forest/AVLTree.hpp>
#include <forest/BinarySearchTree.hpp>template <typename T> forest::AVLTree;
template <typename T> forest::BinarySearchTree;template <typename T> forest::AVLTreeNodeBase;
template <typename T> forest::BinarySearchTreeNodeBase;void PreOrderTraversal(const Callback &callback);
void InOrderTraversal(const Callback &callback);
void PostOrderTraversal(const Callback &callback);
void BreadthFirstTraversal(const Callback &callback);T *Minimum();
T *Maximum();std::size_t Height();
std::size_t Size();void Insert(const T &node);
template <typename Key> void Remove(const Key &key);
template <typename Key> T *Search(const Key &key);void Clear();// #include <forest/AVLTree.hpp>
#include <forest/BinarySearchTree.hpp>
#include <string>
// class Node : public forest::AVLTreeNodeBase<Node> {
class Node : public forest::BinarySearchTreeNodeBase<Node> {
public:
Node() = default;
Node(const int &key, const std::string &value) : mKey(key), mValue(value){};
~Node() = default;
public:
bool operator<(const Node &other) const { return mKey < other.mKey; }
friend bool operator<(const Node &lhs, const int &rhs);
friend bool operator<(const int &lhs, const Node &rhs);
public:
void SetKey(const int &key) { mKey = key; }
void SetValue(const std::string &value) { mValue = value; }
public:
int GetKey() { return mKey; }
std::string GetValue() { return mValue; }
private:
int mKey = 0;
std::string mValue;
};
bool operator<(const Node &lhs, const int &rhs) { return lhs.mKey < rhs; }
bool operator<(const int &lhs, const Node &rhs) { return lhs < rhs.mKey; }
int main() {
// forest::AVLTree<Node> Tree;
forest::BinarySearchTreeNodeBase<Node> Tree;
// TODO
return 0;
}Tree.PreOrderTraversal([](auto &node) {
// TODO
});
Tree.InOrderTraversal([](auto &node) {
// TODO
});
Tree.PostOrderTraversal([](auto &node) {
// TODO
});
Tree.BreadthFirstTraversal([](auto &node) {
// TODO
});auto min = Tree.Minimum();
auto max = Tree.Maximum();auto height = Tree.Height();
auto size = Tree.Size();Tree.Insert(Node(key, value));
Tree.Remove(key);
auto result = Tree.Search(key);
if (result) {
std::cout << "Found" << std::endl;
} else {
std::cout << "Not Found" << std::endl;
}Tree.Clear();- Icon made by Freepik from www.flaticon.com
