-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
51 lines (41 loc) · 1 KB
/
Copy pathgraph.cpp
File metadata and controls
51 lines (41 loc) · 1 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
#include <iostream>
#include <ctime>
#include "sparse_graph.h"
#include "dense_graph.h"
using namespace std;
int main(void){
int n = 20;
int m = 100;
srand(time(NULL));
//sparse graph
sparse_graph g1(n, false);
for(int i = 0; i < m; ++i){
int a = rand()%n;
int b = rand()%n;
g1.add_edge(a, b);
}
for(int v = 0; v < n; ++v){
cout << v << " : ";
sparse_graph::adj_iterator adj(g1, v);
for(int w = adj.begin(); !adj.end(); w = adj.next())
cout << w << " ";
cout << endl;
}
cout << endl;
//dense graph
dense_graph g2(n, false);
for(int i = 0; i < m; ++i){
int a = rand()%n;
int b = rand()%n;
g2.add_edge(a, b);
}
for(int v = 0; v < n; ++v){
cout << v << " : ";
dense_graph::adj_iterator adj(g2, v);
for(int w = adj.begin(); !adj.end(); w = adj.next())
cout << w << " ";
cout << endl;
}
cout << endl;
return 0;
}