Skip to content

Commit a290ae7

Browse files
chore: use iwyu on sorting/**.cpp
1 parent 19d136a commit a290ae7

29 files changed

+186
-142
lines changed

sorting/binary_insertion_sort.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
* \f{bmatrix}{10 &20 &30 &40 &50\f}
4040
*/
4141

42-
#include <algorithm> /// for algorithm functions
43-
#include <cassert> /// for assert
44-
#include <iostream> /// for IO operations
45-
#include <vector> /// for working with vectors
42+
#include <stdint.h> // for int64_t
43+
#include <algorithm> // for is_sorted
44+
#include <cassert> // for assert
45+
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
46+
#include <vector> // for vector
47+
#include <iterator> // for begin, end
4648

4749
/**
4850
* \namespace sorting

sorting/bitonic_sort.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* C++ Program for Bitonic Sort. Note that this program
44
works only when size of input is a power of 2. */
55

6-
#include <algorithm>
7-
#include <iostream>
6+
#include <iostream> // for char_traits, operator<<, basic_ostream, basic_os...
7+
#include <utility> // for swap
88

99
/*The parameter dir indicates the sorting direction, ASCENDING
1010
or DESCENDING; if (a[i] > a[j]) agrees with the direction,

sorting/bogo_sort.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
*
1515
* @author [Deep Raval](https://github.com/imdeep2905)
1616
*/
17-
#include <iostream>
18-
#include <algorithm>
19-
#include <array>
20-
#include <cassert>
21-
#include <random>
17+
#include <iostream> // for operator<<, basic_ostream, cout, char_traits
18+
#include <algorithm> // for is_sorted, shuffle
19+
#include <array> // for array
20+
#include <cassert> // for assert
21+
#include <random> // for random_device, mt19937
22+
#include <cstdlib> // for rand, size_t
2223

2324

2425
/**

sorting/bubble_sort.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ can't get the best status in the code we shared above. This happens on the
3737
optimized bubble sort algorithm. It's right down there.
3838
*/
3939

40-
#include <iostream>
41-
#include <vector>
40+
#include <iostream> // for char_traits, basic_ostream, operator<<, basic_os...
41+
#include <vector> // for vector
42+
#include <utility> // for swap
4243

4344
int main() {
4445
int n;

sorting/cocktail_selection_sort.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// array simultaneously, and swaps it with the lowest and highest available
44
// position iteratively or recursively
55

6-
#include <algorithm>
7-
#include <iostream>
8-
#include <vector>
6+
#include <iostream> // for operator<<, basic_ostream, char_traits, basic_is...
7+
#include <vector> // for vector
8+
#include <utility> // for swap
99

1010
// Iterative Version
1111

sorting/comb_sort.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
*
1616
*/
1717

18-
#include <algorithm>
19-
#include <cassert>
20-
#include <iostream>
18+
#include <algorithm> // for is_sorted, max
19+
#include <cassert> // for assert
20+
#include <iostream> // for char_traits, operator<<, basic_istream::operator>>
21+
#include <utility> // for swap
2122

2223
/**
2324
*

sorting/counting_sort_string.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// C++ Program for counting sort
2-
#include <iostream>
2+
#include <iostream> // for char_traits, basic_ostream, operator<<, basic_is...
3+
#include <string> // for basic_string, string, operator<<, operator>>
34

45
using namespace std;
56

sorting/cycle_sort.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
* @author [TsungHan Ho](https://github.com/dalaoqi)
1212
*/
1313

14-
#include <algorithm> /// for std::is_sorted, std::swap
15-
#include <cassert> /// for assert
16-
#include <cstdint> /// for integral typedefs
17-
#include <iostream> /// for io operations
18-
#include <vector> /// for std::vector
14+
#include <algorithm> // for is_sorted
15+
#include <cassert> // for assert
16+
#include <cstddef> // for size_t
17+
#include <cstdint> // for uint32_t
18+
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
19+
#include <iterator> // for begin, end
20+
#include <utility> // for swap
21+
#include <vector> // for vector
1922

2023
/**
2124
* @namespace sorting

sorting/dnf_sort.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
* @author [Sujal Gupta](https://github.com/heysujal)
1111
*/
1212

13-
#include <algorithm> /// for std::is_sorted
14-
#include <cassert> /// for assert
15-
#include <cstdint> /// for integral typedefs
16-
#include <iostream> /// for std::swap and io operations
17-
#include <vector> /// for std::vector
13+
#include <algorithm> // for is_sorted
14+
#include <cassert> // for assert
15+
#include <cstdint> // for uint64_t
16+
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
17+
#include <vector> // for vector
18+
#include <iterator> // for begin, end
19+
#include <utility> // for swap
1820

1921
/**
2022
* @namespace sorting

sorting/gnome_sort.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
* can be \f$O(n)\f$.
1616
*/
1717

18-
#include <algorithm> // for std::swap
19-
#include <array> // for std::array
20-
#include <cassert> // for assertions
21-
#include <iostream> // for io operations
18+
#include <algorithm> // for is_sorted
19+
#include <array> // for array
20+
#include <cassert> // for assert
21+
#include <iostream> // for operator<<, basic_ostream, cout, char_traits, endl
22+
#include <cstdlib> // for rand, size_t
23+
#include <iterator> // for begin, end
24+
#include <utility> // for swap
2225

2326
/**
2427
* @namespace sorting

sorting/heap_sort.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
* Time Complexity - \f$O(n \log(n))\f$
2121
*
2222
*/
23-
#include <algorithm>
24-
#include <cassert>
25-
#include <iostream>
23+
#include <algorithm> // for is_sorted
24+
#include <cassert> // for assert
25+
#include <iostream> // for operator<<, cout, basic_ostream, basic_ostream:...
26+
#include <utility> // for swap
2627

2728
/**
2829
*

sorting/insertion_sort.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@
3939
* \f{bmatrix}{1 &2 &3 &4 &5\f}
4040
*/
4141

42-
#include <algorithm>
43-
#include <cassert>
44-
#include <iostream>
45-
#include <vector>
42+
#include <stdint.h> // for int32_t
43+
#include <algorithm> // for is_sorted
44+
#include <cassert> // for assert
45+
#include <iostream> // for operator<<, basic_ostream, cout, char_traits, endl
46+
#include <vector> // for vector
47+
#include <cstdlib> // for rand, size_t
48+
#include <iterator> // for begin, end
4649

4750
/** \namespace sorting
4851
* \brief Sorting algorithms

sorting/library_sort.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#include <algorithm>
2-
#include <iostream>
1+
#include <algorithm> // for lower_bound
2+
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
3+
#include <iterator> // for distance
34

45
void librarySort(int *index, int n) {
56
int lib_size, index_pos,

sorting/merge_insertion_sort.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
*
88
* @see Individual algorithms: insertion_sort.cpp and merge_sort.cpp
99
*/
10-
#include <algorithm>
11-
#include <array>
12-
#include <cassert>
13-
#include <ctime>
14-
#include <iostream>
15-
#include <memory>
10+
#include <algorithm> // for is_sorted
11+
#include <array> // for array
12+
#include <cassert> // for assert
13+
#include <ctime> // for size_t, time
14+
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
15+
#include <cstdlib> // for rand, srand
16+
#include <iterator> // for begin, end
1617

1718
/** \namespace sorting
1819
* \brief Sorting algorithms

sorting/non_recursive_merge_sort.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
*
55
* A generic implementation of non-recursive merge sort.
66
*/
7-
#include <cstddef> // for size_t
8-
#include <iostream>
9-
#include <utility> // for std::move & std::remove_reference_t
7+
#include <cstddef> // for size_t
8+
#include <iostream> // for operator<<, basic_ostream, char_traits, basic...
9+
#include <utility> // for move
10+
#include <type_traits> // for remove_reference_t
1011

1112
namespace sorting {
1213
template <class Iterator>

sorting/odd_even_sort.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* C++ implementation Odd Even Sort */
2-
#include <iostream>
3-
#include <vector>
2+
#include <iostream> // for operator<<, char_traits, basic_ostream, basic_is...
3+
#include <vector> // for vector
4+
#include <utility> // for swap
45

56
using namespace std;
67

sorting/pigeonhole_sort.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
* The time Complexity of the algorithm is \f$O(n+N)\f$.
1414
*/
1515

16-
#include <algorithm> //for std::is_sorted
17-
#include <array> //for std::array
18-
#include <cassert> //for assert
19-
#include <iostream> //for io operations
16+
#include <algorithm> // for is_sorted, max_element, min_element
17+
#include <array> // for array
18+
#include <cassert> // for assert
19+
#include <iostream> // for operator<<, char_traits, basic_ostream, basic_o...
20+
#include <cstddef> // for size_t
21+
#include <iterator> // for begin, end
2022

2123
/**
2224
* @namespace sorting

sorting/quick_sort.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
* @author [popoapp](https://github.com/popoapp)
2525
*/
2626

27-
#include <algorithm> /// for std::is_sorted
28-
#include <cassert> /// for std::assert
29-
#include <cstdint> /// for integral typedefs
30-
#include <ctime> /// for std::time
31-
#include <iostream> /// for IO operations
32-
#include <vector> /// for std::vector
27+
#include <algorithm> // for is_sorted
28+
#include <cassert> // for assert
29+
#include <cstdint> // for uint64_t, int64_t
30+
#include <ctime> // for time, size_t
31+
#include <iostream> // for operator<<, cout, basic_ostream, basic_istream:...
32+
#include <vector> // for vector
33+
#include <cstdlib> // for rand, srand, RAND_MAX
34+
#include <iterator> // for begin, end
35+
#include <utility> // for swap
3336

3437
/**
3538
* @brief Sorting algorithms

sorting/quick_sort_3.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@
99
* @author immortal-j
1010
* @author [Krishna Vedala](https://github/kvedala)
1111
*/
12-
#include <algorithm>
13-
#include <cassert>
14-
#include <ctime>
15-
#include <iostream>
16-
#include <vector>
12+
#include <stdint.h> // for int32_t
13+
#include <algorithm> // for is_sorted
14+
#include <cassert> // for assert
15+
#include <ctime> // for size_t, time
16+
#include <iostream> // for operator<<, basic_ostream, char_traits, cout
17+
#include <vector> // for vector
18+
#include <cstdlib> // for rand, srand
19+
#include <iterator> // for begin, end
20+
#include <utility> // for swap
1721

1822
namespace {
1923
/**

sorting/quick_sort_iterative.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
* @author [Sebe324](https://github.com/sebe324)
1111
*/
1212

13-
#include <iostream> /// for std::cout
14-
#include <vector> /// for std::vector
15-
#include <stack> /// for std::stack
16-
#include <algorithm> /// for std::is_sorted
17-
#include <cassert> /// for assert
13+
#include <iostream> // for operator<<, basic_ostream, cout, char_traits
14+
#include <vector> // for vector
15+
#include <stack> // for stack
16+
#include <algorithm> // for is_sorted
17+
#include <cassert> // for assert
18+
#include <iterator> // for begin, end
19+
#include <utility> // for swap
1820

1921

2022
/**

sorting/radix_sort.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#include <cmath>
2-
#include <cstdlib>
3-
#include <cstring>
4-
#include <iostream>
1+
#include <cmath> // for pow
2+
#include <cstring> // for memset
3+
#include <iostream> // for char_traits, basic_ostream, basic_ostream::opera...
54

65
void radixsort(int a[], int n) {
76
int count[10];

sorting/random_pivot_quick_sort.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@
4444
* @author [Nitin Sharma](https://github.com/foo290)
4545
*/
4646

47-
#include <algorithm> /// for std::is_sorted(), std::swap()
48-
#include <array> /// for std::array
49-
#include <cassert> /// for assert
50-
#include <ctime> /// for initializing random number generator
51-
#include <iostream> /// for IO operations
52-
#include <tuple> /// for returning multiple values form a function at once
47+
#include <stdint.h> // for int64_t
48+
#include <stdlib.h> // for rand, srand
49+
#include <algorithm> // for is_sorted
50+
#include <array> // for array
51+
#include <cassert> // for assert
52+
#include <ctime> // for size_t, time
53+
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
54+
#include <tuple> // for make_tuple, tie, tuple
55+
#include <utility> // for swap
5356

5457
/**
5558
* @namespace sorting

sorting/recursive_bubble_sort.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@
5757
* complexity
5858
*/
5959

60-
#include <algorithm> /// for std::is_sorted
61-
#include <array> /// for std::array
62-
#include <cassert> /// for assert
63-
#include <cstdint> /// for integral typedefs
64-
#include <iostream> /// for IO operations
65-
#include <vector> /// for std::vector
60+
#include <algorithm> // for is_sorted
61+
#include <cassert> // for assert
62+
#include <cstdint> // for uint64_t, int64_t
63+
#include <iostream> // for operator<<, basic_ostream, char_traits, cout, endl
64+
#include <vector> // for vector
65+
#include <iterator> // for begin, end
66+
#include <utility> // for swap
6667

6768
/**
6869
* @namespace sorting

sorting/selection_sort_recursive.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
* @author [Tushar Khanduri](https://github.com/Tushar-K24)
2828
*/
2929

30-
#include <algorithm> /// for std::is_sorted
31-
#include <cassert> /// for assert
32-
#include <cstdint> /// for integral typedefs
33-
#include <iostream> /// for std::swap and io operations
34-
#include <vector> /// for std::vector
30+
#include <algorithm> // for is_sorted
31+
#include <cassert> // for assert
32+
#include <cstdint> // for uint64_t
33+
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
34+
#include <vector> // for vector
35+
#include <iterator> // for begin, end
36+
#include <utility> // for swap
3537

3638
/**
3739
* @namespace sorting

0 commit comments

Comments
 (0)