-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdjacencyList.cpp
83 lines (66 loc) · 2.07 KB
/
AdjacencyList.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
Copyright 2019 flak authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <iostream>
#include <flak/graph/AdjacencyList.h>
using namespace std;
void simpleGraph() {
// Building a directed graph when first templated parameter is true,
// otherwise a undirected graph.
flak::Graph<true> g;
g.addVertex();
g.addVertex();
g.addVertex();
g.addVertex();
g.addEdge(0, 1); // 0
g.addEdge(1, 2); // 1
g.addEdge(1, 3); // 2
g.addEdge(3, 2); // 3
// the edges of vertex 1
auto it = g.adjacenciesBegin(1);
for(; it != g.adjacenciesEnd(1); ++it) {
cout << it->vertex() << " ";
cout << it->edge() << endl;
}
cout << endl;
}
void withValue() {
// The second parameter is the value type of edge.
// The third parameter is the value type of vertex.
flak::Graph<true, string, int> g;
g.addVertex(22); // the value of vertex 0 is 22
g.addVertex(33);
g.addVertex(44);
g.addVertex(55);
g.addEdge(0, 1, "edge0"); // 0
g.addEdge(1, 2, "edge1"); // 1
g.addEdge(1, 3, "edge2"); // 2
g.addEdge(3, 2, "edge3"); // 3
auto it = g.adjacenciesBegin(1);
for(; it != g.adjacenciesEnd(1); ++it) {
cout << it->vertex() << " ";
cout << it->edge() << " ";
cout << g.edgeValue(it->edge()) << endl; // edge value
}
cout << endl;
}
void specifySize() {
flak::Graph<true, string, int> g(20);
cout << g.vertexesSize() << endl; // 20
g.addEdge(10, 15, "edge");
cout << g.edgesSize() << endl; // 1
}
int main() {
simpleGraph();
withValue();
specifySize();
}