-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCArcGraph.cpp
43 lines (36 loc) · 1004 Bytes
/
CArcGraph.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
#include "CArcGraph.h"
CArcGraph::CArcGraph(int vertexNum) {
vertexCount = vertexNum;
}
CArcGraph::CArcGraph(const IGraph* graph) {
std::vector<int> temp;
vertexCount = graph->VerticesCount();
for (int i = 0; i < vertexCount; i++) {
graph->GetNextVertices(i, temp);
for (int j = 0; j < temp.size(); j++) {
Edge newEdge(i, temp[j]);
edgesList.push_back(newEdge);
}
temp.clear();
}
}
CArcGraph::~CArcGraph() {}
int CArcGraph::VerticesCount() const {
return vertexCount;
}
void CArcGraph::AddEdge(int from, int to) {
Edge temp(from, to);
edgesList.push_back(temp);
}
void CArcGraph::GetNextVertices(int vertex, std::vector<int>& vertices) const {
for (int i = 0; i < edgesList.size(); i++) {
if (edgesList[i].from == vertex)
vertices.push_back(edgesList[i].to);
}
}
void CArcGraph::GetPrevVertices(int vertex, std::vector<int>& vertices) const {
for (int i = 0; i < edgesList.size(); i++) {
if (edgesList[i].to == vertex)
vertices.push_back(edgesList[i].from);
}
}