-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetGraph.cpp
47 lines (37 loc) · 1004 Bytes
/
SetGraph.cpp
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
#include "SetGraph.h"
SetGraph::SetGraph(int vertices_count) {
vertices.resize(vertices_count);
}
SetGraph::SetGraph(const IGraph &graph) : vertices(graph.VerticesCount()) {
for (int i = 0; i < graph.VerticesCount(); ++i) {
for (auto child: graph.GetNextVertices(i)) {
vertices[i].insert(child);
}
}
}
SetGraph::~SetGraph() {
}
void SetGraph::AddEdge(int from, int to) {
vertices[from].insert(to);
}
int SetGraph::VerticesCount() const {
return vertices.size();
}
std::vector<int> SetGraph::GetNextVertices(int vertex) const {
std::vector<int> result;
for (auto to: vertices[vertex]) {
result.push_back(to);
}
return result;
}
std::vector<int> SetGraph::GetPrevVertices(int vertex) const {
std::vector<int> result;
for (const auto &parent: vertices) {
for (auto child: parent) {
if (child == vertex) {
result.push_back(child);
}
}
}
return result;
}