ECG/exercise1/node.h

36 lines
863 B
C
Raw Normal View History

2019-04-19 12:00:50 +00:00
#ifndef NODE_H
#define NODE_H
#include <vector>
#include <string>
#include <sstream>
#include <functional>
#include <iostream>
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, uint32_t depth = 0);
private:
std::string name;
std::vector<Node*> children;
static uint32_t node_id;
};
extern std::ostream& operator<<(std::ostream &os, const Node *node);
#endif // NODE_H