-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTree.h
More file actions
45 lines (36 loc) · 1.15 KB
/
Tree.h
File metadata and controls
45 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef TREE_H
#define TREE_H
#include "Graph.h"
#include "Node.h"
#include <vector>
/// Represents a tree.
/// @author Abdullah Aghazadah
/// @date 4-24-15
///
/// A Tree, like a Graph, is set of Nodes and a set of Edges. The distinctive feature of a Tree is
/// that it does not contain any cycles.
class Tree{
public:
// constructors
Tree(const Node& root); // constructor must be given a node
Tree(const Graph& graph, const Node& root);
// readers ("getters")
std::vector<Node> pathTo(const Node& node) const;
std::unordered_set<Node> nodes() const;
std::unordered_set<Edge> edges() const;
// modifiers ("setters")
void addChild(const Node& to, const Node& child, int weight);
private:
// main private attributes
Graph graph_;
Node root_;
// private helper attributes
std::unordered_set<Node> visitedNodes_;
// private helper methods
void visit(const Node& node);
bool isVisited(const Node& node);
bool hasUnvisitedChild(const Node& node);
Node anUnvisitedChild(const Node& of);
std::vector<Node> dfs(const Node& node, const Node& target, std::vector<Node> path);
};
#endif // TREE_H