-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.cpp
More file actions
150 lines (136 loc) · 4.16 KB
/
example.cpp
File metadata and controls
150 lines (136 loc) · 4.16 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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include "combinatorial_generators.h"
using namespace std;
void rand_perm_example() {
cout << "rand_perm_example:" << endl;
vector<int> v1;
for (int i = 0; i < 8; i++) {
v1.push_back(i);
}
vector<int> v2 = rand_perm(v1);
for (int i = 0; i < (int)v2.size(); i++) {
cout << v2[i] << " ";
}
cout << endl << endl;
}
void rand_parentheses_example() {
cout << "rand_parentheses_example:" << endl;
int nbPairs = 10;
vector<int> v = rand_parentheses(nbPairs);
for (int i = 0; i < (int)v.size(); i++) {
cout << v[i] << " ";
}
cout << endl << endl;
}
void display_edges(vector< pair<int,int> > edges) {
for (int i = 0; i < (int)edges.size(); i++) {
cout << "(" << edges[i].first << ","<< edges[i].second << ") ";
}
}
void rand_tree_example() {
cout << "rand_tree_example:" << endl;
int nbNodes = 6;
vector< pair<int,int> > edges = rand_tree(nbNodes);
display_edges(edges);
cout << endl << endl;
}
/*
This graph will be used as input for different examples.
The result is on the form (nbNodes, edgeList).
*/
pair<int, vector< pair<int,int> > > small_graph() {
int nbNodes = 8;
vector< pair<int,int> > edges;
edges.push_back(make_pair(0, 1));
edges.push_back(make_pair(0, 2));
edges.push_back(make_pair(1, 3));
edges.push_back(make_pair(2, 3));
edges.push_back(make_pair(3, 4));
edges.push_back(make_pair(4, 5));
edges.push_back(make_pair(4, 6));
edges.push_back(make_pair(5, 7));
edges.push_back(make_pair(6, 7));
return make_pair(nbNodes, edges);
}
void rand_spanning_tree_example() {
cout << "rand_spanning_tree_example:" << endl;
pair<int, vector< pair<int,int> > > g = small_graph();
int nbNodes = g.first;
vector< pair<int,int> > edges = g.second;
vector< pair<int,int> > treeEdges = rand_spanning_tree(nbNodes, edges);
display_edges(treeEdges);
cout << endl << endl;
}
void rand_dfs_tree_example() {
cout << "rand_dfs_tree_example:" << endl;
pair<int, vector< pair<int,int> > > g = small_graph();
int nbNodes = g.first;
int idStart = 0;
vector< pair<int,int> > edges = g.second;
vector< pair<int,int> > treeEdges = rand_dfs_tree(nbNodes, edges, idStart);
display_edges(treeEdges);
cout << endl << endl;
}
void rand_bfs_tree_example() {
cout << "rand_bfs_tree_example:" << endl;
pair<int, vector< pair<int,int> > > g = small_graph();
int nbNodes = g.first;
int idStart = 0;
vector< pair<int,int> > edges = g.second;
vector< pair<int,int> > treeEdges = rand_bfs_tree(nbNodes, edges, idStart);
display_edges(treeEdges);
cout << endl << endl;
}
void rand_dijkstra_tree_example() {
cout << "rand_dijkstra_tree_example:" << endl;
pair<int, vector< pair<int,int> > > g = small_graph();
int nbNodes = g.first;
int idStart = 0;
vector< pair<int,int> > edges = g.second;
vector< pair<int,int> > treeEdges = rand_dijkstra_tree(nbNodes, edges, idStart);
display_edges(treeEdges);
cout << endl << endl;
}
void rand_prim_tree_example() {
cout << "rand_prim_tree_example:" << endl;
pair<int, vector< pair<int,int> > > g = small_graph();
int nbNodes = g.first;
int idStart = 0;
vector< pair<int,int> > edges = g.second;
vector< pair<int,int> > treeEdges = rand_prim_tree(nbNodes, edges, idStart);
display_edges(treeEdges);
cout << endl << endl;
}
void rand_hunt_and_kill_tree_example() {
cout << "rand_hunt_and_kill_tree_example:" << endl;
pair<int, vector< pair<int,int> > > g = small_graph();
int nbNodes = g.first;
int idStart = 0;
vector< pair<int,int> > edges = g.second;
vector< pair<int,int> > treeEdges =
rand_hunt_and_kill_tree(nbNodes, edges, idStart);
display_edges(treeEdges);
cout << endl << endl;
}
void rand_kruskal_tree_example() {
cout << "rand_kruskal_tree_example:" << endl;
pair<int, vector< pair<int,int> > > g = small_graph();
int nbNodes = g.first;
vector< pair<int,int> > edges = g.second;
vector< pair<int,int> > treeEdges = rand_kruskal_tree(nbNodes, edges);
display_edges(treeEdges);
cout << endl << endl;
}
int main() {
rand_perm_example();
rand_parentheses_example();
rand_tree_example();
rand_spanning_tree_example();
rand_dfs_tree_example();
rand_bfs_tree_example();
rand_dijkstra_tree_example();
rand_prim_tree_example();
rand_hunt_and_kill_tree_example();
rand_kruskal_tree_example();
return 0;
}