-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cpp
More file actions
45 lines (31 loc) · 905 Bytes
/
Graph.cpp
File metadata and controls
45 lines (31 loc) · 905 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
43
#include <iostream>
#include <vector>
#include <chrono>
#include <unordered_map>
#include <fstream>
#include "Graph.h"
#include "metrics.h"
using namespace std;
// add_edge_unweighted a method that adds an edge to the graph
void Graph::add_edge_unweighted(int a, int b) {
adj_out[a].push_back(b);
adj_in[b].push_back(a);
}
// create_graph is the method that iteratively adds edges to the graph
void Graph::create_graph(string graph_file) {
ifstream infile(graph_file);
int a, b;
while (infile >> a >> b) {
this->add_edge_unweighted(a, b);
}
infile.close();
}
// print_graph prints the content of a graph
void Graph::print_graph() {
for (auto& x : this->adj_out) {
std::cout << x.first << ": [";
for (auto it = x.second.begin(); it != x.second.end(); ++it)
std::cout << ' ' << *it;
std::cout << "]" << "\n";
}
}