Skip to content

Commit 0ed3409

Browse files
Revert "chore: use iwyu on graph/**.cpp"
This reverts commit dabd6d2.
1 parent fe87144 commit 0ed3409

16 files changed

+163
-176
lines changed

graph/bidirectional_dijkstra.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@
1313
* https://www.youtube.com/watch?v=DINCL5cd_w0&t=24s
1414
*/
1515

16-
#include <cassert> // for assert
17-
#include <cstdint> // for uint64_t, int64_t
18-
#include <iostream> // for basic_ostream, operator<<, char_traits, cout
19-
#include <limits> // for numeric_limits
20-
#include <queue> // for priority_queue
21-
#include <utility> // for pair, make_pair
22-
#include <vector> // for vector
23-
#include <functional> // for greater
16+
#include <cassert> /// for assert
17+
#include <cstdint> /// for integral typedefs
18+
#include <iostream> /// for io operations
19+
#include <limits> /// for variable INF
20+
#include <queue> /// for the priority_queue of distances
21+
#include <utility> /// for make_pair function
22+
#include <vector> /// for store the graph, the distances, and the path
2423

2524
constexpr int64_t INF = std::numeric_limits<int64_t>::max();
2625

graph/breadth_first_search.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
* push that element into the queue and mark this as visited
4646
*
4747
*/
48-
#include <cassert> // for assert
49-
#include <cstddef> // for size_t
50-
#include <functional> // for less
51-
#include <iostream> // for basic_ostream, operator<<, cout, basic_istream...
52-
#include <list> // for list
53-
#include <map> // for map, operator==
54-
#include <queue> // for queue
55-
#include <string> // for basic_string, operator<, char_traits, allocator
48+
#include <algorithm>
49+
#include <cassert>
50+
#include <iostream>
51+
#include <list>
52+
#include <map>
53+
#include <queue>
54+
#include <string>
55+
#include <vector>
5656

5757
/**
5858
* \namespace graph

graph/connected_components.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
*
2626
*/
2727

28-
#include <cassert> // for assert
29-
#include <iostream> // for basic_ostream, char_traits, operator<<, basic_is...
30-
#include <vector> // for vector
28+
#include <algorithm>
29+
#include <cassert>
30+
#include <iostream>
31+
#include <vector>
3132

3233
/**
3334
* @namespace graph

graph/connected_components_with_dsu.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
* @author Unknown author
1818
* @author [Sagar Pandya](https://github.com/sagarpandyansit)
1919
*/
20-
#include <cstdint> // for int64_t, uint32_t
21-
#include <iostream> // for char_traits, basic_istream, cin, basic_ostream
22-
#include <set> // for set
23-
#include <vector> // for vector
24-
#include <utility> // for swap
20+
#include <cstdint> /// for integer typedefs
21+
#include <iostream> /// for IO operations
22+
#include <set> /// for std::set
23+
#include <vector> /// for std::vector
2524

2625
/**
2726
* @namespace graph

graph/cycle_check_directed_graph.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
*
88
*/
99

10-
#include <cstdint> // for uint8_t
11-
#include <iostream> // for char_traits, basic_ostream, operator<<
12-
#include <map> // for map, operator!=, _Rb_tree_iterator
13-
#include <queue> // for queue
14-
#include <stdexcept> // for range_error
15-
#include <type_traits> // for remove_reference
16-
#include <utility> // for move, pair
17-
#include <vector> // for vector
18-
#include <initializer_list> // for initializer_list
10+
#include <cstdint> /// for integral typedefs
11+
#include <iostream> // for std::cout
12+
#include <map> // for std::map
13+
#include <queue> // for std::queue
14+
#include <stdexcept> // for throwing errors
15+
#include <type_traits> // for std::remove_reference
16+
#include <utility> // for std::move
17+
#include <vector> // for std::vector
1918

2019
/**
2120
* Implementation of non-weighted directed edge of a graph.

graph/depth_first_search.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
*
3333
*/
3434

35-
#include <cstddef> // for size_t
36-
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
37-
#include <vector> // for vector
35+
#include <algorithm>
36+
#include <iostream>
37+
#include <vector>
3838

3939
/**
4040
*

graph/depth_first_search_with_stack.cpp

Lines changed: 80 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
*
33
* @file
44
* @brief [Depth First Search Algorithm using Stack
5-
* (Depth First Search
6-
* Algorithm)](https://en.wikipedia.org/wiki/Depth-first_search)
5+
* (Depth First Search Algorithm)](https://en.wikipedia.org/wiki/Depth-first_search)
76
*
87
* @author [Ayaan Khan](http://github.com/ayaankhan98)
98
* @author [Saurav Uppoor](https://github.com/sauravUppoor)
@@ -25,35 +24,31 @@
2524
* <h4>Working</h4>
2625
* 1. Mark all vertices as unvisited (colour it WHITE).
2726
* 2. Push starting vertex into the stack and colour it GREY.
28-
* 3. Once a node is popped out of the stack and is coloured GREY, we colour it
29-
* BLACK.
27+
* 3. Once a node is popped out of the stack and is coloured GREY, we colour it BLACK.
3028
* 4. Push all its neighbours which are not coloured BLACK.
3129
* 5. Repeat steps 4 and 5 until the stack is empty.
3230
*/
3331

34-
#include <stdint.h> // for int16_t, int64_t
32+
#include <iostream> /// for IO operations
33+
#include <stack> /// header for std::stack
34+
#include <vector> /// header for std::vector
35+
#include <cassert> /// header for preprocessor macro assert()
36+
#include <limits> /// header for limits of integral types
3537

36-
#include <cassert> // for assert
37-
#include <cstddef> // for size_t
38-
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
39-
#include <limits> // for numeric_limits
40-
#include <stack> // for stack
41-
#include <vector> // for vector, operator==
42-
43-
constexpr int WHITE = 0; /// indicates the node hasn't been explored
44-
constexpr int GREY = 1; /// indicates node is in stack waiting to be explored
45-
constexpr int BLACK = 2; /// indicates node has already been explored
38+
constexpr int WHITE = 0; /// indicates the node hasn't been explored
39+
constexpr int GREY = 1; /// indicates node is in stack waiting to be explored
40+
constexpr int BLACK = 2; /// indicates node has already been explored
4641
constexpr int64_t INF = std::numeric_limits<int16_t>::max();
4742

43+
4844
/**
4945
* @namespace graph
5046
* @brief Graph algorithms
5147
*/
5248
namespace graph {
5349
/**
5450
* @namespace depth_first_search
55-
* @brief Functions for [Depth First
56-
* Search](https://en.wikipedia.org/wiki/Depth-first_search) algorithm
51+
* @brief Functions for [Depth First Search](https://en.wikipedia.org/wiki/Depth-first_search) algorithm
5752
*/
5853
namespace depth_first_search {
5954
/**
@@ -67,14 +62,14 @@ namespace depth_first_search {
6762
*
6863
*/
6964
void addEdge(std::vector<std::vector<size_t>> *adj, size_t u, size_t v) {
70-
/*
71-
*
72-
* Here we are considering undirected graph that's the
73-
* reason we are adding v to the adjacency list representation of u
74-
* and also adding u to the adjacency list representation of v
75-
*
76-
*/
77-
(*adj)[u - 1].push_back(v - 1);
65+
/*
66+
*
67+
* Here we are considering undirected graph that's the
68+
* reason we are adding v to the adjacency list representation of u
69+
* and also adding u to the adjacency list representation of v
70+
*
71+
*/
72+
(*adj)[u - 1].push_back(v - 1);
7873
}
7974

8075
/**
@@ -89,8 +84,7 @@ void addEdge(std::vector<std::vector<size_t>> *adj, size_t u, size_t v) {
8984
* @return vector with nodes stored in the order of DFS traversal
9085
*
9186
*/
92-
std::vector<size_t> dfs(const std::vector<std::vector<size_t>> &graph,
93-
size_t start) {
87+
std::vector<size_t> dfs(const std::vector<std::vector<size_t> > &graph, size_t start) {
9488
/// checked[i] stores the status of each node
9589
std::vector<size_t> checked(graph.size(), WHITE), traversed_path;
9690

@@ -127,51 +121,49 @@ std::vector<size_t> dfs(const std::vector<std::vector<size_t>> &graph,
127121
* @returns none
128122
*/
129123
static void tests() {
130-
size_t start_pos;
131-
132-
/// Test 1
133-
std::cout << "Case 1: " << std::endl;
134-
start_pos = 1;
135-
std::vector<std::vector<size_t>> g1(3, std::vector<size_t>());
136-
137-
graph::depth_first_search::addEdge(&g1, 1, 2);
138-
graph::depth_first_search::addEdge(&g1, 2, 3);
139-
graph::depth_first_search::addEdge(&g1, 3, 1);
140-
141-
std::vector<size_t> expected1{
142-
1, 2, 3}; /// for the above sample data, this is the expected output
143-
assert(graph::depth_first_search::dfs(g1, start_pos - 1) == expected1);
144-
std::cout << "Passed" << std::endl;
145-
146-
/// Test 2
147-
std::cout << "Case 2: " << std::endl;
148-
start_pos = 1;
149-
std::vector<std::vector<size_t>> g2(4, std::vector<size_t>());
150-
151-
graph::depth_first_search::addEdge(&g2, 1, 2);
152-
graph::depth_first_search::addEdge(&g2, 1, 3);
153-
graph::depth_first_search::addEdge(&g2, 2, 4);
154-
graph::depth_first_search::addEdge(&g2, 4, 1);
155-
156-
std::vector<size_t> expected2{
157-
1, 3, 2, 4}; /// for the above sample data, this is the expected output
158-
assert(graph::depth_first_search::dfs(g2, start_pos - 1) == expected2);
159-
std::cout << "Passed" << std::endl;
160-
161-
/// Test 3
162-
std::cout << "Case 3: " << std::endl;
163-
start_pos = 2;
164-
std::vector<std::vector<size_t>> g3(4, std::vector<size_t>());
165-
166-
graph::depth_first_search::addEdge(&g3, 1, 2);
167-
graph::depth_first_search::addEdge(&g3, 1, 3);
168-
graph::depth_first_search::addEdge(&g3, 2, 4);
169-
graph::depth_first_search::addEdge(&g3, 4, 1);
170-
171-
std::vector<size_t> expected3{
172-
2, 4, 1, 3}; /// for the above sample data, this is the expected output
173-
assert(graph::depth_first_search::dfs(g3, start_pos - 1) == expected3);
174-
std::cout << "Passed" << std::endl;
124+
size_t start_pos;
125+
126+
/// Test 1
127+
std::cout << "Case 1: " << std::endl;
128+
start_pos = 1;
129+
std::vector<std::vector<size_t> > g1(3, std::vector<size_t>());
130+
131+
graph::depth_first_search::addEdge(&g1, 1, 2);
132+
graph::depth_first_search::addEdge(&g1, 2, 3);
133+
graph::depth_first_search::addEdge(&g1, 3, 1);
134+
135+
std::vector<size_t> expected1 {1, 2, 3}; /// for the above sample data, this is the expected output
136+
assert(graph::depth_first_search::dfs(g1, start_pos - 1) == expected1);
137+
std::cout << "Passed" << std::endl;
138+
139+
/// Test 2
140+
std::cout << "Case 2: " << std::endl;
141+
start_pos = 1;
142+
std::vector<std::vector<size_t> > g2(4, std::vector<size_t>());
143+
144+
graph::depth_first_search::addEdge(&g2, 1, 2);
145+
graph::depth_first_search::addEdge(&g2, 1, 3);
146+
graph::depth_first_search::addEdge(&g2, 2, 4);
147+
graph::depth_first_search::addEdge(&g2, 4, 1);
148+
149+
std::vector<size_t> expected2 {1, 3, 2, 4}; /// for the above sample data, this is the expected output
150+
assert(graph::depth_first_search::dfs(g2, start_pos - 1) == expected2);
151+
std::cout << "Passed" << std::endl;
152+
153+
/// Test 3
154+
std::cout << "Case 3: " << std::endl;
155+
start_pos = 2;
156+
std::vector<std::vector<size_t> > g3(4, std::vector<size_t>());
157+
158+
graph::depth_first_search::addEdge(&g3, 1, 2);
159+
graph::depth_first_search::addEdge(&g3, 1, 3);
160+
graph::depth_first_search::addEdge(&g3, 2, 4);
161+
graph::depth_first_search::addEdge(&g3, 4, 1);
162+
163+
std::vector<size_t> expected3 {2, 4, 1, 3}; /// for the above sample data, this is the expected output
164+
assert(graph::depth_first_search::dfs(g3, start_pos - 1) == expected3);
165+
std::cout << "Passed" << std::endl;
166+
175167
}
176168

177169
/**
@@ -182,35 +174,34 @@ int main() {
182174
tests(); // execute the tests
183175

184176
size_t vertices = 0, edges = 0, start_pos = 1;
185-
std::vector<size_t> traversal;
177+
std::vector<size_t> traversal;
186178

187179
std::cout << "Enter the Vertices : ";
188-
std::cin >> vertices;
189-
std::cout << "Enter the Edges : ";
190-
std::cin >> edges;
180+
std::cin >> vertices;
181+
std::cout << "Enter the Edges : ";
182+
std::cin >> edges;
191183

192184
/// creating a graph
193-
std::vector<std::vector<size_t>> adj(vertices, std::vector<size_t>());
185+
std::vector<std::vector<size_t> > adj(vertices, std::vector<size_t>());
194186

195187
/// taking input for the edges
196-
std::cout << "Enter the vertices which have edges between them : "
197-
<< std::endl;
198-
while (edges--) {
199-
size_t u = 0, v = 0;
200-
std::cin >> u >> v;
201-
graph::depth_first_search::addEdge(&adj, u, v);
202-
}
188+
std::cout << "Enter the vertices which have edges between them : " << std::endl;
189+
while (edges--) {
190+
size_t u = 0, v = 0;
191+
std::cin >> u >> v;
192+
graph::depth_first_search::addEdge(&adj, u, v);
193+
}
203194

204195
/// taking input for the starting position
205196
std::cout << "Enter the starting vertex [1,n]: " << std::endl;
206-
std::cin >> start_pos;
207-
start_pos -= 1;
208-
traversal = graph::depth_first_search::dfs(adj, start_pos);
197+
std::cin >> start_pos;
198+
start_pos -= 1;
199+
traversal = graph::depth_first_search::dfs(adj, start_pos);
209200

210201
/// Printing the order of traversal
211202
for (auto x : traversal) {
212-
std::cout << x << ' ';
213-
}
203+
std::cout << x << ' ';
204+
}
214205

215206
return 0;
216207
}

graph/dijkstra.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
* at the code below to understand in better way.
2424
*
2525
*/
26-
#include <stdint.h> // for int64_t
27-
#include <cassert> // for assert
28-
#include <iostream> // for basic_ostream, char_traits, operator<<, basic_...
29-
#include <limits> // for numeric_limits
30-
#include <queue> // for priority_queue
31-
#include <utility> // for pair, make_pair
32-
#include <vector> // for vector
33-
#include <functional> // for greater
26+
#include <cassert>
27+
#include <iostream>
28+
#include <limits>
29+
#include <memory>
30+
#include <queue>
31+
#include <utility>
32+
#include <vector>
3433

3534
constexpr int64_t INF = std::numeric_limits<int64_t>::max();
3635

graph/hamiltons_cycle.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
* @author [vakhokoto](https://github.com/vakhokoto)
1616
* @author [Krishna Vedala](https://github.com/kvedala)
1717
*/
18-
#include <cassert> // for assert
19-
#include <cstddef> // for size_t
20-
#include <iostream> // for operator<<, basic_ostream, cout
21-
#include <vector> // for vector
18+
#include <cassert>
19+
#include <iostream>
20+
#include <vector>
2221

2322
/**
2423
* The function determines if there is a hamilton's cycle in the graph

0 commit comments

Comments
 (0)