-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArcGraph.cpp
47 lines (36 loc) · 1004 Bytes
/
ArcGraph.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 "ArcGraph.h"
ArcGraph::ArcGraph(int vertices_count) : vertices_count(vertices_count) {
}
ArcGraph::ArcGraph(const IGraph &graph) : vertices_count(graph.VerticesCount()) {
for (int i = 0; i < graph.VerticesCount(); ++i) {
for (auto child: graph.GetNextVertices(i)) {
edges.emplace_back(i, child);
}
}
}
ArcGraph::~ArcGraph() {
}
void ArcGraph::AddEdge(int from, int to) {
edges.emplace_back(from, to);
}
int ArcGraph::VerticesCount() const {
return vertices_count;
}
std::vector<int> ArcGraph::GetNextVertices(int vertex) const {
std::vector<int> result;
for (auto edge: edges) {
if (edge.first == vertex) {
result.push_back(edge.second);
}
}
return result;
}
std::vector<int> ArcGraph::GetPrevVertices(int vertex) const {
std::vector<int> result;
for (auto edge: edges) {
if (edge.second == vertex) {
result.push_back(edge.first);
}
}
return result;
}