diff --git a/sorting/binary_insertion_sort.cpp b/sorting/binary_insertion_sort.cpp index f0404c6b4..fbba2ec1e 100644 --- a/sorting/binary_insertion_sort.cpp +++ b/sorting/binary_insertion_sort.cpp @@ -39,10 +39,12 @@ * \f{bmatrix}{10 &20 &30 &40 &50\f} */ -#include /// for algorithm functions -#include /// for assert -#include /// for IO operations -#include /// for working with vectors +#include // for int64_t +#include // for is_sorted +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector +#include // for begin, end /** * \namespace sorting diff --git a/sorting/bitonic_sort.cpp b/sorting/bitonic_sort.cpp index 0fbb995ac..a3eb37f2c 100644 --- a/sorting/bitonic_sort.cpp +++ b/sorting/bitonic_sort.cpp @@ -3,8 +3,8 @@ /* C++ Program for Bitonic Sort. Note that this program works only when size of input is a power of 2. */ -#include -#include +#include // for char_traits, operator<<, basic_ostream, basic_os... +#include // for swap /*The parameter dir indicates the sorting direction, ASCENDING or DESCENDING; if (a[i] > a[j]) agrees with the direction, diff --git a/sorting/bogo_sort.cpp b/sorting/bogo_sort.cpp index 749eaddd0..b13939286 100644 --- a/sorting/bogo_sort.cpp +++ b/sorting/bogo_sort.cpp @@ -14,11 +14,12 @@ * * @author [Deep Raval](https://github.com/imdeep2905) */ -#include -#include -#include -#include -#include +#include // for operator<<, basic_ostream, cout, char_traits +#include // for is_sorted, shuffle +#include // for array +#include // for assert +#include // for random_device, mt19937 +#include // for rand, size_t /** diff --git a/sorting/bubble_sort.cpp b/sorting/bubble_sort.cpp index c43e425fc..71e6b528a 100644 --- a/sorting/bubble_sort.cpp +++ b/sorting/bubble_sort.cpp @@ -37,8 +37,9 @@ can't get the best status in the code we shared above. This happens on the optimized bubble sort algorithm. It's right down there. */ -#include -#include +#include // for char_traits, basic_ostream, operator<<, basic_os... +#include // for vector +#include // for swap int main() { int n; diff --git a/sorting/cocktail_selection_sort.cpp b/sorting/cocktail_selection_sort.cpp index 157acafce..6c912cef0 100644 --- a/sorting/cocktail_selection_sort.cpp +++ b/sorting/cocktail_selection_sort.cpp @@ -3,9 +3,9 @@ // array simultaneously, and swaps it with the lowest and highest available // position iteratively or recursively -#include -#include -#include +#include // for operator<<, basic_ostream, char_traits, basic_is... +#include // for vector +#include // for swap // Iterative Version diff --git a/sorting/comb_sort.cpp b/sorting/comb_sort.cpp index 3fee36d6a..43125a6df 100644 --- a/sorting/comb_sort.cpp +++ b/sorting/comb_sort.cpp @@ -15,9 +15,10 @@ * */ -#include -#include -#include +#include // for is_sorted, max +#include // for assert +#include // for char_traits, operator<<, basic_istream::operator>> +#include // for swap /** * diff --git a/sorting/counting_sort_string.cpp b/sorting/counting_sort_string.cpp index 69d80c18a..92f693f08 100644 --- a/sorting/counting_sort_string.cpp +++ b/sorting/counting_sort_string.cpp @@ -1,5 +1,6 @@ // C++ Program for counting sort -#include +#include // for char_traits, basic_ostream, operator<<, basic_is... +#include // for basic_string, string, operator<<, operator>> using namespace std; diff --git a/sorting/cycle_sort.cpp b/sorting/cycle_sort.cpp index 1371fac94..964419743 100644 --- a/sorting/cycle_sort.cpp +++ b/sorting/cycle_sort.cpp @@ -11,11 +11,14 @@ * @author [TsungHan Ho](https://github.com/dalaoqi) */ -#include /// for std::is_sorted, std::swap -#include /// for assert -#include /// for integral typedefs -#include /// for io operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for size_t +#include // for uint32_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for begin, end +#include // for swap +#include // for vector /** * @namespace sorting diff --git a/sorting/dnf_sort.cpp b/sorting/dnf_sort.cpp index 3cdb1c34e..4e52367d1 100644 --- a/sorting/dnf_sort.cpp +++ b/sorting/dnf_sort.cpp @@ -10,11 +10,13 @@ * @author [Sujal Gupta](https://github.com/heysujal) */ -#include /// for std::is_sorted -#include /// for assert -#include /// for integral typedefs -#include /// for std::swap and io operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/gnome_sort.cpp b/sorting/gnome_sort.cpp index d56662479..5decd52fd 100644 --- a/sorting/gnome_sort.cpp +++ b/sorting/gnome_sort.cpp @@ -15,10 +15,13 @@ * can be \f$O(n)\f$. */ -#include // for std::swap -#include // for std::array -#include // for assertions -#include // for io operations +#include // for is_sorted +#include // for array +#include // for assert +#include // for operator<<, basic_ostream, cout, char_traits, endl +#include // for rand, size_t +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/heap_sort.cpp b/sorting/heap_sort.cpp index d91cdb14f..150f710d0 100644 --- a/sorting/heap_sort.cpp +++ b/sorting/heap_sort.cpp @@ -20,9 +20,10 @@ * Time Complexity - \f$O(n \log(n))\f$ * */ -#include -#include -#include +#include // for is_sorted +#include // for assert +#include // for operator<<, cout, basic_ostream, basic_ostream:... +#include // for swap /** * diff --git a/sorting/insertion_sort.cpp b/sorting/insertion_sort.cpp index c9bac4bf7..94f4ff58c 100644 --- a/sorting/insertion_sort.cpp +++ b/sorting/insertion_sort.cpp @@ -39,10 +39,13 @@ * \f{bmatrix}{1 &2 &3 &4 &5\f} */ -#include -#include -#include -#include +#include // for int32_t +#include // for is_sorted +#include // for assert +#include // for operator<<, basic_ostream, cout, char_traits, endl +#include // for vector +#include // for rand, size_t +#include // for begin, end /** \namespace sorting * \brief Sorting algorithms diff --git a/sorting/library_sort.cpp b/sorting/library_sort.cpp index 33f151b29..c2f5c96ef 100644 --- a/sorting/library_sort.cpp +++ b/sorting/library_sort.cpp @@ -1,5 +1,6 @@ -#include -#include +#include // for lower_bound +#include // for char_traits, basic_ostream, operator<<, cout +#include // for distance void librarySort(int *index, int n) { int lib_size, index_pos, diff --git a/sorting/merge_insertion_sort.cpp b/sorting/merge_insertion_sort.cpp index 07b2ed19d..441989c25 100644 --- a/sorting/merge_insertion_sort.cpp +++ b/sorting/merge_insertion_sort.cpp @@ -7,12 +7,13 @@ * * @see Individual algorithms: insertion_sort.cpp and merge_sort.cpp */ -#include -#include -#include -#include -#include -#include +#include // for is_sorted +#include // for array +#include // for assert +#include // for size_t, time +#include // for char_traits, basic_ostream, operator<<, cout +#include // for rand, srand +#include // for begin, end /** \namespace sorting * \brief Sorting algorithms diff --git a/sorting/non_recursive_merge_sort.cpp b/sorting/non_recursive_merge_sort.cpp index b99b93108..9ab1c744f 100644 --- a/sorting/non_recursive_merge_sort.cpp +++ b/sorting/non_recursive_merge_sort.cpp @@ -4,9 +4,10 @@ * * A generic implementation of non-recursive merge sort. */ -#include // for size_t -#include -#include // for std::move & std::remove_reference_t +#include // for size_t +#include // for operator<<, basic_ostream, char_traits, basic... +#include // for move +#include // for remove_reference_t namespace sorting { template diff --git a/sorting/odd_even_sort.cpp b/sorting/odd_even_sort.cpp index 25f2a3712..38ce8d0f1 100644 --- a/sorting/odd_even_sort.cpp +++ b/sorting/odd_even_sort.cpp @@ -1,6 +1,7 @@ /* C++ implementation Odd Even Sort */ -#include -#include +#include // for operator<<, char_traits, basic_ostream, basic_is... +#include // for vector +#include // for swap using namespace std; diff --git a/sorting/pigeonhole_sort.cpp b/sorting/pigeonhole_sort.cpp index 764365b86..a560f417b 100644 --- a/sorting/pigeonhole_sort.cpp +++ b/sorting/pigeonhole_sort.cpp @@ -13,10 +13,12 @@ * The time Complexity of the algorithm is \f$O(n+N)\f$. */ -#include //for std::is_sorted -#include //for std::array -#include //for assert -#include //for io operations +#include // for is_sorted, max_element, min_element +#include // for array +#include // for assert +#include // for operator<<, char_traits, basic_ostream, basic_o... +#include // for size_t +#include // for begin, end /** * @namespace sorting diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 88d01ea14..d2da9737b 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -24,12 +24,15 @@ * @author [popoapp](https://github.com/popoapp) */ -#include /// for std::is_sorted -#include /// for std::assert -#include /// for integral typedefs -#include /// for std::time -#include /// for IO operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t, int64_t +#include // for time, size_t +#include // for operator<<, cout, basic_ostream, basic_istream:... +#include // for vector +#include // for rand, srand, RAND_MAX +#include // for begin, end +#include // for swap /** * @brief Sorting algorithms diff --git a/sorting/quick_sort_3.cpp b/sorting/quick_sort_3.cpp index 72dc44d9b..8e212fe25 100644 --- a/sorting/quick_sort_3.cpp +++ b/sorting/quick_sort_3.cpp @@ -9,11 +9,15 @@ * @author immortal-j * @author [Krishna Vedala](https://github/kvedala) */ -#include -#include -#include -#include -#include +#include // for int32_t +#include // for is_sorted +#include // for assert +#include // for size_t, time +#include // for operator<<, basic_ostream, char_traits, cout +#include // for vector +#include // for rand, srand +#include // for begin, end +#include // for swap namespace { /** diff --git a/sorting/quick_sort_iterative.cpp b/sorting/quick_sort_iterative.cpp index da506c9c0..f6a8751c3 100644 --- a/sorting/quick_sort_iterative.cpp +++ b/sorting/quick_sort_iterative.cpp @@ -10,11 +10,13 @@ * @author [Sebe324](https://github.com/sebe324) */ -#include /// for std::cout -#include /// for std::vector -#include /// for std::stack -#include /// for std::is_sorted -#include /// for assert +#include // for operator<<, basic_ostream, cout, char_traits +#include // for vector +#include // for stack +#include // for is_sorted +#include // for assert +#include // for begin, end +#include // for swap /** diff --git a/sorting/radix_sort.cpp b/sorting/radix_sort.cpp index a0fbfe99e..d6e16cc80 100644 --- a/sorting/radix_sort.cpp +++ b/sorting/radix_sort.cpp @@ -1,7 +1,6 @@ -#include -#include -#include -#include +#include // for pow +#include // for memset +#include // for char_traits, basic_ostream, basic_ostream::opera... void radixsort(int a[], int n) { int count[10]; diff --git a/sorting/random_pivot_quick_sort.cpp b/sorting/random_pivot_quick_sort.cpp index a6ed19f12..9ea2ede6c 100644 --- a/sorting/random_pivot_quick_sort.cpp +++ b/sorting/random_pivot_quick_sort.cpp @@ -44,12 +44,15 @@ * @author [Nitin Sharma](https://github.com/foo290) */ -#include /// for std::is_sorted(), std::swap() -#include /// for std::array -#include /// for assert -#include /// for initializing random number generator -#include /// for IO operations -#include /// for returning multiple values form a function at once +#include // for int64_t +#include // for rand, srand +#include // for is_sorted +#include // for array +#include // for assert +#include // for size_t, time +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for make_tuple, tie, tuple +#include // for swap /** * @namespace sorting diff --git a/sorting/recursive_bubble_sort.cpp b/sorting/recursive_bubble_sort.cpp index 5b860f833..c5eac9337 100644 --- a/sorting/recursive_bubble_sort.cpp +++ b/sorting/recursive_bubble_sort.cpp @@ -57,12 +57,13 @@ * complexity */ -#include /// for std::is_sorted -#include /// for std::array -#include /// for assert -#include /// for integral typedefs -#include /// for IO operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t, int64_t +#include // for operator<<, basic_ostream, char_traits, cout, endl +#include // for vector +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/selection_sort_recursive.cpp b/sorting/selection_sort_recursive.cpp index 765b97098..7232c5f7b 100644 --- a/sorting/selection_sort_recursive.cpp +++ b/sorting/selection_sort_recursive.cpp @@ -27,11 +27,13 @@ * @author [Tushar Khanduri](https://github.com/Tushar-K24) */ -#include /// for std::is_sorted -#include /// for assert -#include /// for integral typedefs -#include /// for std::swap and io operations -#include /// for std::vector +#include // for is_sorted +#include // for assert +#include // for uint64_t +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector +#include // for begin, end +#include // for swap /** * @namespace sorting diff --git a/sorting/shell_sort2.cpp b/sorting/shell_sort2.cpp index 5db773aca..e8abc619f 100644 --- a/sorting/shell_sort2.cpp +++ b/sorting/shell_sort2.cpp @@ -3,12 +3,11 @@ * \brief [Shell sort](https://en.wikipedia.org/wiki/Shell_sort) algorithm * \author [Krishna Vedala](https://github.com/kvedala) */ -#include -#include -#include -#include -#include // for std::swap -#include +#include // for assert +#include // for rand, size_t, qsort, srand, NULL, atoi +#include // for clock, clock_t, CLOCKS_PER_SEC, time +#include // for operator<<, basic_ostream, char_traits, cout, endl +#include // for vector /** pretty print array * \param[in] arr array to print diff --git a/sorting/stooge_sort.cpp b/sorting/stooge_sort.cpp index b1f01321a..1bb72bdcd 100644 --- a/sorting/stooge_sort.cpp +++ b/sorting/stooge_sort.cpp @@ -1,7 +1,7 @@ /** * @file - * @brief [Stooge sort implementation](https://en.wikipedia.org/wiki/Stooge_sort) - * in C++ + * @brief [Stooge sort + *implementation](https://en.wikipedia.org/wiki/Stooge_sort) in C++ * @details * Stooge sort is a recursive sorting algorithm. * It divides the array into 3 parts and proceeds to: @@ -13,18 +13,21 @@ * on the street on average. Space complexity is O(1). */ -#include /// for vector -#include /// for assert -#include /// for std::is_sorted -#include /// for IO operations +#include // for is_sorted +#include // for assert +#include // for size_t +#include // for operator<<, basic_ostream, cout +#include // for begin, end +#include // for swap +#include // for vector - /** - * @brief The stoogeSort() function is used for sorting the array. - * @param L - vector of values (int) to be sorted in in place (ascending order) - * @param i - the first index of the array (0) - * @param j - the last index of the array (L.size() - 1) - * @returns void - */ +/** + * @brief The stoogeSort() function is used for sorting the array. + * @param L - vector of values (int) to be sorted in in place (ascending order) + * @param i - the first index of the array (0) + * @param j - the last index of the array (L.size() - 1) + * @returns void + */ void stoogeSort(std::vector* L, size_t i, size_t j) { if (i >= j) { return; @@ -45,9 +48,9 @@ void stoogeSort(std::vector* L, size_t i, size_t j) { * @returns void */ void test1() { - std::vector L = { 8, 9, 10, 4, 3, 5, 1 }; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = {8, 9, 10, 4, 3, 5, 1}; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -55,9 +58,9 @@ void test1() { * @returns void */ void test2() { - std::vector L = { -1 }; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = {-1}; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -65,9 +68,9 @@ void test2() { * @returns void */ void test3() { - std::vector L = { 1, 2, 5, 4, 1, 5 }; - stoogeSort(&L, 0, L.size() - 1); - assert(std::is_sorted(std::begin(L), std::end(L))); + std::vector L = {1, 2, 5, 4, 1, 5}; + stoogeSort(&L, 0, L.size() - 1); + assert(std::is_sorted(std::begin(L), std::end(L))); } /** @@ -77,10 +80,10 @@ void test3() { * @returns 0 on exit */ int main() { - test1(); - test2(); - test3(); - + test1(); + test2(); + test3(); + std::cout << "All tests have successfully passed!\n"; - return 0; + return 0; } diff --git a/sorting/tim_sort.cpp b/sorting/tim_sort.cpp index 03ccf3808..51b06eca4 100644 --- a/sorting/tim_sort.cpp +++ b/sorting/tim_sort.cpp @@ -1,8 +1,9 @@ // C++ program to perform TimSort. -#include -#include -#include -#include +#include // for printf +#include // for min, is_sorted, reverse +#include // for assert +#include // for basic_ostream, cout, endl +#include // for iota const int RUN = 32; diff --git a/sorting/wave_sort.cpp b/sorting/wave_sort.cpp index 85fdb61ad..7b92f3fed 100644 --- a/sorting/wave_sort.cpp +++ b/sorting/wave_sort.cpp @@ -8,10 +8,12 @@ * @author [Swastika Gupta](https://github.com/Swastyy) */ -#include /// for std::is_sorted, std::swap -#include /// for assert -#include /// for IO operations -#include /// for std::vector +#include // for int64_t +#include // for sort +#include // for assert +#include // for basic_ostream, operator<<, char_traits, cout, endl +#include // for vector, operator==, allocator +#include // for swap /** * @namespace sorting diff --git a/sorting/wiggle_sort.cpp b/sorting/wiggle_sort.cpp index fe5009bb4..a0c252cbe 100644 --- a/sorting/wiggle_sort.cpp +++ b/sorting/wiggle_sort.cpp @@ -17,12 +17,13 @@ * arr = [2,8,9,1,7], after wiggle sort arr will become equal to [8,2,9,1,7] */ -#include -#include -#include /// for integral typedefs -#include -#include /// for io operations -#include +#include // for assert +#include // for uint32_t +#include // for time +#include // for operator<<, basic_ostream, char_traits, cout, endl +#include // for vector +#include // for rand, srand +#include // for swap /** * @namespace sorting