mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-14 10:50:13 +08:00
chore: use iwyu on sorting/**.cpp
This commit is contained in:
@@ -39,10 +39,12 @@
|
||||
* \f{bmatrix}{10 &20 &30 &40 &50\f}
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for algorithm functions
|
||||
#include <cassert> /// for assert
|
||||
#include <iostream> /// for IO operations
|
||||
#include <vector> /// for working with vectors
|
||||
#include <stdint.h> // for int64_t
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
|
||||
#include <vector> // for vector
|
||||
#include <iterator> // for begin, end
|
||||
|
||||
/**
|
||||
* \namespace sorting
|
||||
|
||||
@@ -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 <algorithm>
|
||||
#include <iostream>
|
||||
#include <iostream> // for char_traits, operator<<, basic_ostream, basic_os...
|
||||
#include <utility> // for swap
|
||||
|
||||
/*The parameter dir indicates the sorting direction, ASCENDING
|
||||
or DESCENDING; if (a[i] > a[j]) agrees with the direction,
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
*
|
||||
* @author [Deep Raval](https://github.com/imdeep2905)
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <random>
|
||||
#include <iostream> // for operator<<, basic_ostream, cout, char_traits
|
||||
#include <algorithm> // for is_sorted, shuffle
|
||||
#include <array> // for array
|
||||
#include <cassert> // for assert
|
||||
#include <random> // for random_device, mt19937
|
||||
#include <cstdlib> // for rand, size_t
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 <iostream>
|
||||
#include <vector>
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<, basic_os...
|
||||
#include <vector> // for vector
|
||||
#include <utility> // for swap
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// array simultaneously, and swaps it with the lowest and highest available
|
||||
// position iteratively or recursively
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <iostream> // for operator<<, basic_ostream, char_traits, basic_is...
|
||||
#include <vector> // for vector
|
||||
#include <utility> // for swap
|
||||
|
||||
// Iterative Version
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <algorithm> // for is_sorted, max
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for char_traits, operator<<, basic_istream::operator>>
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// C++ Program for counting sort
|
||||
#include <iostream>
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<, basic_is...
|
||||
#include <string> // for basic_string, string, operator<<, operator>>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -11,11 +11,14 @@
|
||||
* @author [TsungHan Ho](https://github.com/dalaoqi)
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for std::is_sorted, std::swap
|
||||
#include <cassert> /// for assert
|
||||
#include <cstdint> /// for integral typedefs
|
||||
#include <iostream> /// for io operations
|
||||
#include <vector> /// for std::vector
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <cstddef> // for size_t
|
||||
#include <cstdint> // for uint32_t
|
||||
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
#include <vector> // for vector
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
* @author [Sujal Gupta](https://github.com/heysujal)
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for std::is_sorted
|
||||
#include <cassert> /// for assert
|
||||
#include <cstdint> /// for integral typedefs
|
||||
#include <iostream> /// for std::swap and io operations
|
||||
#include <vector> /// for std::vector
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for uint64_t
|
||||
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
|
||||
#include <vector> // for vector
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -15,10 +15,13 @@
|
||||
* can be \f$O(n)\f$.
|
||||
*/
|
||||
|
||||
#include <algorithm> // for std::swap
|
||||
#include <array> // for std::array
|
||||
#include <cassert> // for assertions
|
||||
#include <iostream> // for io operations
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <array> // for array
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for operator<<, basic_ostream, cout, char_traits, endl
|
||||
#include <cstdlib> // for rand, size_t
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -20,9 +20,10 @@
|
||||
* Time Complexity - \f$O(n \log(n))\f$
|
||||
*
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for operator<<, cout, basic_ostream, basic_ostream:...
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -39,10 +39,13 @@
|
||||
* \f{bmatrix}{1 &2 &3 &4 &5\f}
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdint.h> // for int32_t
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for operator<<, basic_ostream, cout, char_traits, endl
|
||||
#include <vector> // for vector
|
||||
#include <cstdlib> // for rand, size_t
|
||||
#include <iterator> // for begin, end
|
||||
|
||||
/** \namespace sorting
|
||||
* \brief Sorting algorithms
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <algorithm> // for lower_bound
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
|
||||
#include <iterator> // for distance
|
||||
|
||||
void librarySort(int *index, int n) {
|
||||
int lib_size, index_pos,
|
||||
|
||||
@@ -7,12 +7,13 @@
|
||||
*
|
||||
* @see Individual algorithms: insertion_sort.cpp and merge_sort.cpp
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <array> // for array
|
||||
#include <cassert> // for assert
|
||||
#include <ctime> // for size_t, time
|
||||
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
|
||||
#include <cstdlib> // for rand, srand
|
||||
#include <iterator> // for begin, end
|
||||
|
||||
/** \namespace sorting
|
||||
* \brief Sorting algorithms
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
*
|
||||
* A generic implementation of non-recursive merge sort.
|
||||
*/
|
||||
#include <cstddef> // for size_t
|
||||
#include <iostream>
|
||||
#include <utility> // for std::move & std::remove_reference_t
|
||||
#include <cstddef> // for size_t
|
||||
#include <iostream> // for operator<<, basic_ostream, char_traits, basic...
|
||||
#include <utility> // for move
|
||||
#include <type_traits> // for remove_reference_t
|
||||
|
||||
namespace sorting {
|
||||
template <class Iterator>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* C++ implementation Odd Even Sort */
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <iostream> // for operator<<, char_traits, basic_ostream, basic_is...
|
||||
#include <vector> // for vector
|
||||
#include <utility> // for swap
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -13,10 +13,12 @@
|
||||
* The time Complexity of the algorithm is \f$O(n+N)\f$.
|
||||
*/
|
||||
|
||||
#include <algorithm> //for std::is_sorted
|
||||
#include <array> //for std::array
|
||||
#include <cassert> //for assert
|
||||
#include <iostream> //for io operations
|
||||
#include <algorithm> // for is_sorted, max_element, min_element
|
||||
#include <array> // for array
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for operator<<, char_traits, basic_ostream, basic_o...
|
||||
#include <cstddef> // for size_t
|
||||
#include <iterator> // for begin, end
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -24,12 +24,15 @@
|
||||
* @author [popoapp](https://github.com/popoapp)
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for std::is_sorted
|
||||
#include <cassert> /// for std::assert
|
||||
#include <cstdint> /// for integral typedefs
|
||||
#include <ctime> /// for std::time
|
||||
#include <iostream> /// for IO operations
|
||||
#include <vector> /// for std::vector
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for uint64_t, int64_t
|
||||
#include <ctime> // for time, size_t
|
||||
#include <iostream> // for operator<<, cout, basic_ostream, basic_istream:...
|
||||
#include <vector> // for vector
|
||||
#include <cstdlib> // for rand, srand, RAND_MAX
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @brief Sorting algorithms
|
||||
|
||||
@@ -9,11 +9,15 @@
|
||||
* @author immortal-j
|
||||
* @author [Krishna Vedala](https://github/kvedala)
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <stdint.h> // for int32_t
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <ctime> // for size_t, time
|
||||
#include <iostream> // for operator<<, basic_ostream, char_traits, cout
|
||||
#include <vector> // for vector
|
||||
#include <cstdlib> // for rand, srand
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
|
||||
namespace {
|
||||
/**
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
* @author [Sebe324](https://github.com/sebe324)
|
||||
*/
|
||||
|
||||
#include <iostream> /// for std::cout
|
||||
#include <vector> /// for std::vector
|
||||
#include <stack> /// for std::stack
|
||||
#include <algorithm> /// for std::is_sorted
|
||||
#include <cassert> /// for assert
|
||||
#include <iostream> // for operator<<, basic_ostream, cout, char_traits
|
||||
#include <vector> // for vector
|
||||
#include <stack> // for stack
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cmath> // for pow
|
||||
#include <cstring> // for memset
|
||||
#include <iostream> // for char_traits, basic_ostream, basic_ostream::opera...
|
||||
|
||||
void radixsort(int a[], int n) {
|
||||
int count[10];
|
||||
|
||||
@@ -44,12 +44,15 @@
|
||||
* @author [Nitin Sharma](https://github.com/foo290)
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for std::is_sorted(), std::swap()
|
||||
#include <array> /// for std::array
|
||||
#include <cassert> /// for assert
|
||||
#include <ctime> /// for initializing random number generator
|
||||
#include <iostream> /// for IO operations
|
||||
#include <tuple> /// for returning multiple values form a function at once
|
||||
#include <stdint.h> // for int64_t
|
||||
#include <stdlib.h> // for rand, srand
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <array> // for array
|
||||
#include <cassert> // for assert
|
||||
#include <ctime> // for size_t, time
|
||||
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
|
||||
#include <tuple> // for make_tuple, tie, tuple
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -57,12 +57,13 @@
|
||||
* complexity
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for std::is_sorted
|
||||
#include <array> /// for std::array
|
||||
#include <cassert> /// for assert
|
||||
#include <cstdint> /// for integral typedefs
|
||||
#include <iostream> /// for IO operations
|
||||
#include <vector> /// for std::vector
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for uint64_t, int64_t
|
||||
#include <iostream> // for operator<<, basic_ostream, char_traits, cout, endl
|
||||
#include <vector> // for vector
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -27,11 +27,13 @@
|
||||
* @author [Tushar Khanduri](https://github.com/Tushar-K24)
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for std::is_sorted
|
||||
#include <cassert> /// for assert
|
||||
#include <cstdint> /// for integral typedefs
|
||||
#include <iostream> /// for std::swap and io operations
|
||||
#include <vector> /// for std::vector
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for uint64_t
|
||||
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
|
||||
#include <vector> // for vector
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
* \brief [Shell sort](https://en.wikipedia.org/wiki/Shell_sort) algorithm
|
||||
* \author [Krishna Vedala](https://github.com/kvedala)
|
||||
*/
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <utility> // for std::swap
|
||||
#include <vector>
|
||||
#include <cassert> // for assert
|
||||
#include <cstdlib> // for rand, size_t, qsort, srand, NULL, atoi
|
||||
#include <ctime> // for clock, clock_t, CLOCKS_PER_SEC, time
|
||||
#include <iostream> // for operator<<, basic_ostream, char_traits, cout, endl
|
||||
#include <vector> // for vector
|
||||
|
||||
/** pretty print array
|
||||
* \param[in] arr array to print
|
||||
|
||||
@@ -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 <vector> /// for vector
|
||||
#include <cassert> /// for assert
|
||||
#include <algorithm> /// for std::is_sorted
|
||||
#include <iostream> /// for IO operations
|
||||
#include <algorithm> // for is_sorted
|
||||
#include <cassert> // for assert
|
||||
#include <cstddef> // for size_t
|
||||
#include <iostream> // for operator<<, basic_ostream, cout
|
||||
#include <iterator> // for begin, end
|
||||
#include <utility> // for swap
|
||||
#include <vector> // 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<int>* L, size_t i, size_t j) {
|
||||
if (i >= j) {
|
||||
return;
|
||||
@@ -45,9 +48,9 @@ void stoogeSort(std::vector<int>* L, size_t i, size_t j) {
|
||||
* @returns void
|
||||
*/
|
||||
void test1() {
|
||||
std::vector<int> 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<int> 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<int> L = { -1 };
|
||||
stoogeSort(&L, 0, L.size() - 1);
|
||||
assert(std::is_sorted(std::begin(L), std::end(L)));
|
||||
std::vector<int> 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<int> 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<int> 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;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// C++ program to perform TimSort.
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <stdio.h> // for printf
|
||||
#include <algorithm> // for min, is_sorted, reverse
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for basic_ostream, cout, endl
|
||||
#include <numeric> // for iota
|
||||
|
||||
const int RUN = 32;
|
||||
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
* @author [Swastika Gupta](https://github.com/Swastyy)
|
||||
*/
|
||||
|
||||
#include <algorithm> /// for std::is_sorted, std::swap
|
||||
#include <cassert> /// for assert
|
||||
#include <iostream> /// for IO operations
|
||||
#include <vector> /// for std::vector
|
||||
#include <stdint.h> // for int64_t
|
||||
#include <algorithm> // for sort
|
||||
#include <cassert> // for assert
|
||||
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
|
||||
#include <vector> // for vector, operator==, allocator
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
@@ -17,12 +17,13 @@
|
||||
* arr = [2,8,9,1,7], after wiggle sort arr will become equal to [8,2,9,1,7]
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint> /// for integral typedefs
|
||||
#include <ctime>
|
||||
#include <iostream> /// for io operations
|
||||
#include <vector>
|
||||
#include <cassert> // for assert
|
||||
#include <cstdint> // for uint32_t
|
||||
#include <ctime> // for time
|
||||
#include <iostream> // for operator<<, basic_ostream, char_traits, cout, endl
|
||||
#include <vector> // for vector
|
||||
#include <cstdlib> // for rand, srand
|
||||
#include <utility> // for swap
|
||||
|
||||
/**
|
||||
* @namespace sorting
|
||||
|
||||
Reference in New Issue
Block a user