-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadData.cpp
56 lines (46 loc) · 1.08 KB
/
readData.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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "readData.h"
using namespace std;
vector<vector<int>> read_Data(const int& argc, const char* const* argv) {
if (argc < 2) {
cout << "Usage: " << argv[0] << " input_file.extension\n";
}
char p;
string edge;
int vertices, edges;
// Open the input file
ifstream File(argv[1]);
// Read 'p' and 'edge'
File >> p >> edge;
// Read the number of vertices and the number of edges
File >> vertices >> edges;
vector<vector<int>> G(vertices);
char e;
int u, v;
while (File >> e) {
if (e == 'e') {
// Read an edge (u, v)
File >> u >> v;
// Add v to the adjacency list of u
G[u-1].emplace_back(v-1);
// Add u to the adjacency list of v
G[v-1].emplace_back(u-1);
}
}
// Close the input file
File.close();
/*
// Print the Graph
for (int u = 0; u < vertices; u++) {
cout << u+1 << ": ";
for (int v : G[u]) {
cout << v+1 << " ";
}
cout << endl;
}
*/
return G;
}