-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.h
More file actions
31 lines (28 loc) · 993 Bytes
/
graph.h
File metadata and controls
31 lines (28 loc) · 993 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
#ifndef CPP_ALGORITHM_GRAPH_H
#define CPP_ALGORITHM_GRAPH_H
namespace Graph
{
auto InitializeAdjacencyMatrix(int row, int col, std::vector<std::vector<int, int>>& edges)
-> std::vector<std::vector<int>>
{
auto adjacency_matrix = std::vector<std::vector<int>>(row, std::vector<int>(col, 0));
for (const auto& [x, y] : edges)
{
if (x < row && y < col)
{
adjacency_matrix[x][y] = 1;
}
}
return adjacency_matrix;
}
auto InitializeAdjacencyMatrixWithZero(int row, int col) -> std::vector<std::vector<int>>
{
auto adjacency_matrix = std::vector<std::vector<int>>(row, std::vector<int>(col, 0));
return adjacency_matrix;
}
auto InitializeAdjacencyMatrixWithOne(int row, int col) -> std::vector<std::vector<int>>
{
auto adjacency_matrix = std::vector<std::vector<int>>(row, std::vector<int>(col, 1));
return adjacency_matrix;
}
}