forked from HPI-Artificial-Intelligence-Teaching/24-pt2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
digraph_test.cpp
54 lines (47 loc) · 1.2 KB
/
digraph_test.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
/******************************************************************************
*
* A directed graph, implemented using an array of sets. Parallel edges and self-loops allowed.
*
* Based on the source code from Robert Sedgewick and Kevin Wayne at https://algs4.cs.princeton.edu/
*
* % ./digraph_test ../data/tinyDG.txt
* 13 vertices, 22 edges
* 0: 5 1
* 1:
* 2: 0 3
* 3: 5 2
* 4: 3 2
* 5: 4
* 6: 9 4 8 0
* 7: 6 9
* 8: 6
* 9: 11 10
* 10: 12
* 11: 4 12
* 12: 9
*
******************************************************************************/
#include "digraph.h"
#include <fstream>
#include <iostream>
using namespace std;
// main entry point of the program
int main(int argc, char* argv[]) {
// parameter check
if (argc != 2) {
cerr << "Invalid command line. Expecting one argument of input file name." << endl;
return (1);
}
// read the digraph from the file
ifstream graph_file;
graph_file.open(argv[1]);
if (!graph_file) {
cerr << "Unable to open file " << argv[1] << endl;
return (1);
}
Digraph dg(graph_file);
graph_file.close();
// output the digraph on the screen
cout << dg << endl;
return (0);
}