forked from JamesMcCrae/flatfab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.h
61 lines (42 loc) · 1.06 KB
/
tree.h
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef TREE_H
#define TREE_H
#include <QVector>
#include <QList>
#include <QDebug>
struct TreeNode {
TreeNode():
index(0),
parent(-1),
visited(0)
{
}
int index;
int parent;
QList <int> children;
int visited;
};
class Tree
{
public:
Tree();
void CreateFromGraph(const QVector <QVector <bool> > & graph, const int root_node);
int GetNumNodes();
bool IsConnected();
bool HasCycles();
int GetRoot();
bool HasParent(const int i);
int GetParent(const int i);
void GetChildren(const int i, QList <int> & children);
void GetBranch(const int i, QList <int> & branch);
void GetCycles(QList <QList <int> > & cycles);
void GetDisconnectedNodes(QList <int> & disc_nodes);
private:
void GetPathToRoot(const int i, QList <int> & path);
void TraceBackCycle(const int i1, const int i2, QList <int> & cycle);
bool is_connected;
bool has_cycles;
QVector <TreeNode> nodes;
QList <QList <int> > cycles;
QList <int> disconnected_nodes;
};
#endif // TREE_H