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