-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArcGraph.cpp
More file actions
42 lines (35 loc) · 975 Bytes
/
Copy pathArcGraph.cpp
File metadata and controls
42 lines (35 loc) · 975 Bytes
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
#include <ArcGraph.h>
FromTo::FromTo(int from, int to) {
this->from = from;
this->to = to;
}
ArcGraph::ArcGraph(size_t node_count) : count(node_count) {}
ArcGraph::ArcGraph(const IGraph &graph) {
count = graph.VerticesCount();
for (int from = 0; from < static_cast<int>(count); ++from) {
std::vector<int> to = graph.GetNextVertices(from);
for (int side : to) {
AddEdge(from, side);
}
}
}
void ArcGraph::AddEdge(int from, int to) { sides.push_back(FromTo(from, to)); }
int ArcGraph::VerticesCount() const { return count; }
std::vector<int> ArcGraph::GetNextVertices(int vertex) const {
std::vector<int> res = {};
for (FromTo side : sides) {
if (side.from == vertex) {
res.push_back(side.to);
}
}
return res;
}
std::vector<int> ArcGraph::GetPrevVertices(int vertex) const {
std::vector<int> res = {};
for (FromTo side : sides) {
if (side.to == vertex) {
res.push_back(side.from);
}
}
return res;
}