diff --git a/sorting/cycle_sort.cpp b/sorting/cycle_sort.cpp index 8acf462af..1371fac94 100644 --- a/sorting/cycle_sort.cpp +++ b/sorting/cycle_sort.cpp @@ -13,6 +13,7 @@ #include /// for std::is_sorted, std::swap #include /// for assert +#include /// for integral typedefs #include /// for io operations #include /// for std::vector diff --git a/sorting/dnf_sort.cpp b/sorting/dnf_sort.cpp index 8b7c2279e..3cdb1c34e 100644 --- a/sorting/dnf_sort.cpp +++ b/sorting/dnf_sort.cpp @@ -12,6 +12,7 @@ #include /// for std::is_sorted #include /// for assert +#include /// for integral typedefs #include /// for std::swap and io operations #include /// for std::vector diff --git a/sorting/quick_sort.cpp b/sorting/quick_sort.cpp index 514361444..88d01ea14 100644 --- a/sorting/quick_sort.cpp +++ b/sorting/quick_sort.cpp @@ -26,6 +26,7 @@ #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 diff --git a/sorting/radix_sort2.cpp b/sorting/radix_sort2.cpp index 3d6916e16..84dd6911f 100644 --- a/sorting/radix_sort2.cpp +++ b/sorting/radix_sort2.cpp @@ -23,8 +23,10 @@ */ /// header files + #include /// for collection of functions #include /// for a macro called assert which can be used to verify assumptions +#include /// for integral typedefs #include /// for io operations #include /// for std::vector diff --git a/sorting/recursive_bubble_sort.cpp b/sorting/recursive_bubble_sort.cpp index d76a72d86..5b860f833 100644 --- a/sorting/recursive_bubble_sort.cpp +++ b/sorting/recursive_bubble_sort.cpp @@ -1,20 +1,23 @@ /** * @file * @author [Aditya Prakash](https://adityaprakash.tech) - * @brief This is an implementation of a recursive version of the [Bubble sort algorithm](https://www.geeksforgeeks.org/recursive-bubble-sort/) + * @brief This is an implementation of a recursive version of the [Bubble sort + algorithm](https://www.geeksforgeeks.org/recursive-bubble-sort/) * * @details * The working principle of the Bubble sort algorithm. - * Bubble sort is a simple sorting algorithm used to rearrange a set of ascending or descending order elements. - * Bubble sort gets its name from the fact that data "bubbles" to the top of the dataset. - + * Bubble sort is a simple sorting algorithm used to rearrange a set of + ascending or descending order elements. + * Bubble sort gets its name from the fact that data "bubbles" to the top of the + dataset. + * ### Algorithm * What is Swap? * Swapping two numbers means that we interchange their values. - * Often, an additional variable is required for this operation. + * Often, an additional variable is required for this operation. * This is further illustrated in the following: * void swap(int x, int y){ @@ -26,15 +29,19 @@ * The above process is a typical displacement process. * When we assign a value to x, the old value of x is lost. * That's why we create a temporary variable z to store the initial value of x. - * z is further used to assign the initial value of x to y, to complete swapping. + * z is further used to assign the initial value of x to y, to complete + swapping. * Recursion - * While the recursive method does not necessarily have advantages over iterative + * While the recursive method does not necessarily have advantages over + iterative * versions, but it is useful to enhance the understanding of the algorithm and * recursion itself. In Recursive Bubble sort algorithm, we firstly call the - * function on the entire array, and for every subsequent function call, we exclude - * the last element. This fixes the last element for that sub-array.Formally, for + * function on the entire array, and for every subsequent function call, we + exclude + * the last element. This fixes the last element for that sub-array.Formally, + for * `ith` iteration, we consider elements up to n-i, where n is the number of * elements in the array. Exit condition: n==1; i.e. the sub-array contains only * one element. @@ -43,16 +50,19 @@ * Time complexity: O(n) best case; O(n²) average case; O(n²) worst case * Space complexity: O(n) - * We need to traverse the array `n * (n-1)` times. However, if the entire array is - * already sorted, then we need to traverse it only once. Hence, O(n) is the best case + * We need to traverse the array `n * (n-1)` times. However, if the entire array + is + * already sorted, then we need to traverse it only once. Hence, O(n) is the + best case * complexity */ -#include /// for assert -#include /// for IO operations -#include /// for std::vector -#include /// for std::array -#include /// for std::is_sorted +#include /// for std::is_sorted +#include /// for std::array +#include /// for assert +#include /// for integral typedefs +#include /// for IO operations +#include /// for std::vector /** * @namespace sorting @@ -61,11 +71,11 @@ namespace sorting { /** - * @brief This is an implementation of the recursive_bubble_sort. A vector is passed - * to the function which is then dereferenced, so that the changes are + * @brief This is an implementation of the recursive_bubble_sort. A vector is + * passed to the function which is then dereferenced, so that the changes are * reflected in the original vector. It also accepts a second parameter of * type `int` and name `n`, which is the size of the array. - * + * * @tparam T type of data variables in the array * @param nums our array of elements. * @param n size of the array @@ -136,14 +146,13 @@ static void test() { std::cout << double_arr[i] << ", "; } std::cout << std::endl; - } /** * @brief Main function * @returns 0 on exit */ -int main() { +int main() { test(); // run self-test implementations return 0; } diff --git a/sorting/selection_sort_iterative.cpp b/sorting/selection_sort_iterative.cpp index a9adac089..c25dac981 100644 --- a/sorting/selection_sort_iterative.cpp +++ b/sorting/selection_sort_iterative.cpp @@ -29,6 +29,7 @@ *******************************************************************************/ #include /// for std::is_sorted #include /// for std::assert +#include /// for integral typedefs #include /// for IO operations #include /// for std::vector diff --git a/sorting/selection_sort_recursive.cpp b/sorting/selection_sort_recursive.cpp index 57eadfbd0..80f9ac719 100644 --- a/sorting/selection_sort_recursive.cpp +++ b/sorting/selection_sort_recursive.cpp @@ -28,9 +28,10 @@ */ #include /// for std::is_sorted -#include /// for assert -#include /// for std::swap and io operations -#include /// for std::vector +#include /// for assert#include /// for integral typedefs +#include /// for integral typedefs +#include /// for std::swap and io operations +#include /// for std::vector /** * @namespace sorting diff --git a/sorting/wiggle_sort.cpp b/sorting/wiggle_sort.cpp index bf8574c98..fe5009bb4 100644 --- a/sorting/wiggle_sort.cpp +++ b/sorting/wiggle_sort.cpp @@ -19,6 +19,7 @@ #include #include +#include /// for integral typedefs #include #include /// for io operations #include @@ -50,7 +51,7 @@ namespace wiggle_sort { */ template // this allows to have vectors of ints, double, float, // etc - std::vector wiggleSort(const std::vector &arr) { +std::vector wiggleSort(const std::vector &arr) { uint32_t size = arr.size(); std::vector out(