-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.h
More file actions
79 lines (52 loc) · 1.82 KB
/
Graph.h
File metadata and controls
79 lines (52 loc) · 1.82 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <memory>
#include "WeightedLink.h"
#ifndef GRAPH_H
#define GRAPH_H
class Graph {
public:
std::vector<std::vector<int>> adjMatrix;
std::vector<std::vector<int>> strongPaths;
// vector to track those nodes that have been visited during dfs
std::vector<int> tracker;
// size of the matrix
size_t vertices;
Graph(size_t numVert) {
vertices = numVert;
// Define the size for the order and adjMatrix vector
adjMatrix = std::vector<std::vector<int>>(vertices, std::vector<int>(vertices, -1));
strongPaths = std::vector<std::vector<int>>(vertices, std::vector<int>(vertices, -1));
tracker = std::vector<int>(numVert, 0);
}
~Graph() {}
std::vector<std::vector<int>> getStrongPaths() {
return this->strongPaths;
}
void DisplayAdjMatrix() {
for(int i = 0; i < adjMatrix.size(); ++i) {
for(int j = 0; j < adjMatrix.at(0).size(); ++j) {
std::cout << adjMatrix.at(i).at(j) << " ";
}
std::cout << std::endl;
}
}
void DisplayStrongPaths() {
for(int i = 0; i < strongPaths.size(); ++i) {
for(int j = 0; j < strongPaths.at(0).size(); ++j) {
std::cout << strongPaths.at(i).at(j) << " ";
}
std::cout << std::endl;
}
}
void ResetTracker() {
tracker = std::vector<int>(vertices, 0);
}
bool AddLink(int currentNode, int nextNode, int weight) {
adjMatrix.at(currentNode).at(nextNode) = weight;
return true;
}
};
#endif // GRAPH_H