41 lines
No EOL
1.2 KiB
C++
41 lines
No EOL
1.2 KiB
C++
#ifndef NODE_H
|
|
#define NODE_H
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <set>
|
|
|
|
class Node
|
|
{
|
|
|
|
public:
|
|
Node(const std::string &name = "");
|
|
virtual ~Node();
|
|
|
|
std::string get_name() const;
|
|
void set_name(const std::string &new_name);
|
|
|
|
int get_nr_children() const;
|
|
Node *get_child(int i) const;
|
|
void add_child(Node *child);
|
|
|
|
void print(std::ostream &str = std::cout, uint32_t depth = 0) const;
|
|
static Node *create_complete_tree(uint32_t nr_child_nodes, uint32_t tree_depth);
|
|
static void traverse_tree(const Node *node, std::function<void(const Node *, uint32_t)> predicate, bool recursive, uint32_t depth = 0);
|
|
|
|
private:
|
|
std::string name;
|
|
std::vector<Node *> children;
|
|
|
|
static uint32_t node_id;
|
|
|
|
static void traverse_tree_recursive(const Node *node, std::function<void(const Node *, uint32_t)> predicate, std::set<const Node *> &visited, uint32_t depth = 0);
|
|
static void traverse_tree_iterative(const Node *node, std::function<void(const Node *, uint32_t)> predicate, uint32_t depth = 0);
|
|
};
|
|
|
|
extern std::ostream &operator<<(std::ostream &os, const Node *node);
|
|
|
|
#endif // NODE_H
|