Skip to content

Commit 4707b72

Browse files
fix: add <cstdint> to sorting/**
1 parent 52ff5e8 commit 4707b72

8 files changed

+42
-25
lines changed

sorting/cycle_sort.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <algorithm> /// for std::is_sorted, std::swap
1515
#include <cassert> /// for assert
16+
#include <cstdint> /// for integral typedefs
1617
#include <iostream> /// for io operations
1718
#include <vector> /// for std::vector
1819

sorting/dnf_sort.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <algorithm> /// for std::is_sorted
1414
#include <cassert> /// for assert
15+
#include <cstdint> /// for integral typedefs
1516
#include <iostream> /// for std::swap and io operations
1617
#include <vector> /// for std::vector
1718

sorting/quick_sort.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <algorithm> /// for std::is_sorted
2828
#include <cassert> /// for std::assert
29+
#include <cstdint> /// for integral typedefs
2930
#include <ctime> /// for std::time
3031
#include <iostream> /// for IO operations
3132
#include <vector> /// for std::vector

sorting/radix_sort2.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
*/
2424

2525
/// header files
26+
2627
#include <algorithm> /// for collection of functions
2728
#include <cassert> /// for a macro called assert which can be used to verify assumptions
29+
#include <cstdint> /// for integral typedefs
2830
#include <iostream> /// for io operations
2931
#include <vector> /// for std::vector
3032

sorting/recursive_bubble_sort.cpp

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
/**
22
* @file
33
* @author [Aditya Prakash](https://adityaprakash.tech)
4-
* @brief This is an implementation of a recursive version of the [Bubble sort algorithm](https://www.geeksforgeeks.org/recursive-bubble-sort/)
4+
* @brief This is an implementation of a recursive version of the [Bubble sort
5+
algorithm](https://www.geeksforgeeks.org/recursive-bubble-sort/)
56
*
67
* @details
78
* The working principle of the Bubble sort algorithm.
89
9-
* Bubble sort is a simple sorting algorithm used to rearrange a set of ascending or descending order elements.
10-
* Bubble sort gets its name from the fact that data "bubbles" to the top of the dataset.
11-
10+
* Bubble sort is a simple sorting algorithm used to rearrange a set of
11+
ascending or descending order elements.
12+
* Bubble sort gets its name from the fact that data "bubbles" to the top of the
13+
dataset.
14+
1215
* ### Algorithm
1316
1417
* What is Swap?
1518
1619
* Swapping two numbers means that we interchange their values.
17-
* Often, an additional variable is required for this operation.
20+
* Often, an additional variable is required for this operation.
1821
* This is further illustrated in the following:
1922
2023
* void swap(int x, int y){
@@ -26,15 +29,19 @@
2629
* The above process is a typical displacement process.
2730
* When we assign a value to x, the old value of x is lost.
2831
* That's why we create a temporary variable z to store the initial value of x.
29-
* z is further used to assign the initial value of x to y, to complete swapping.
32+
* z is further used to assign the initial value of x to y, to complete
33+
swapping.
3034
3135
* Recursion
3236
33-
* While the recursive method does not necessarily have advantages over iterative
37+
* While the recursive method does not necessarily have advantages over
38+
iterative
3439
* versions, but it is useful to enhance the understanding of the algorithm and
3540
* recursion itself. In Recursive Bubble sort algorithm, we firstly call the
36-
* function on the entire array, and for every subsequent function call, we exclude
37-
* the last element. This fixes the last element for that sub-array.Formally, for
41+
* function on the entire array, and for every subsequent function call, we
42+
exclude
43+
* the last element. This fixes the last element for that sub-array.Formally,
44+
for
3845
* `ith` iteration, we consider elements up to n-i, where n is the number of
3946
* elements in the array. Exit condition: n==1; i.e. the sub-array contains only
4047
* one element.
@@ -43,16 +50,19 @@
4350
* Time complexity: O(n) best case; O(n²) average case; O(n²) worst case
4451
* Space complexity: O(n)
4552
46-
* We need to traverse the array `n * (n-1)` times. However, if the entire array is
47-
* already sorted, then we need to traverse it only once. Hence, O(n) is the best case
53+
* We need to traverse the array `n * (n-1)` times. However, if the entire array
54+
is
55+
* already sorted, then we need to traverse it only once. Hence, O(n) is the
56+
best case
4857
* complexity
4958
*/
5059

51-
#include <cassert> /// for assert
52-
#include <iostream> /// for IO operations
53-
#include <vector> /// for std::vector
54-
#include <array> /// for std::array
55-
#include <algorithm> /// for std::is_sorted
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
5666

5767
/**
5868
* @namespace sorting
@@ -61,11 +71,11 @@
6171
namespace sorting {
6272

6373
/**
64-
* @brief This is an implementation of the recursive_bubble_sort. A vector is passed
65-
* to the function which is then dereferenced, so that the changes are
74+
* @brief This is an implementation of the recursive_bubble_sort. A vector is
75+
* passed to the function which is then dereferenced, so that the changes are
6676
* reflected in the original vector. It also accepts a second parameter of
6777
* type `int` and name `n`, which is the size of the array.
68-
*
78+
*
6979
* @tparam T type of data variables in the array
7080
* @param nums our array of elements.
7181
* @param n size of the array
@@ -136,14 +146,13 @@ static void test() {
136146
std::cout << double_arr[i] << ", ";
137147
}
138148
std::cout << std::endl;
139-
140149
}
141150

142151
/**
143152
* @brief Main function
144153
* @returns 0 on exit
145154
*/
146-
int main() {
155+
int main() {
147156
test(); // run self-test implementations
148157
return 0;
149158
}

sorting/selection_sort_iterative.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*******************************************************************************/
3030
#include <algorithm> /// for std::is_sorted
3131
#include <cassert> /// for std::assert
32+
#include <cstdint> /// for integral typedefs
3233
#include <iostream> /// for IO operations
3334
#include <vector> /// for std::vector
3435

sorting/selection_sort_recursive.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
*/
2929

3030
#include <algorithm> /// for std::is_sorted
31-
#include <cassert> /// for assert
32-
#include <iostream> /// for std::swap and io operations
33-
#include <vector> /// for std::vector
31+
#include <cassert> /// for assert#include <cstdint> /// for integral typedefs
32+
#include <cstdint> /// for integral typedefs
33+
#include <iostream> /// for std::swap and io operations
34+
#include <vector> /// for std::vector
3435

3536
/**
3637
* @namespace sorting

sorting/wiggle_sort.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <algorithm>
2121
#include <cassert>
22+
#include <cstdint> /// for integral typedefs
2223
#include <ctime>
2324
#include <iostream> /// for io operations
2425
#include <vector>
@@ -50,7 +51,7 @@ namespace wiggle_sort {
5051
*/
5152
template <typename T> // this allows to have vectors of ints, double, float,
5253
// etc
53-
std::vector<T> wiggleSort(const std::vector<T> &arr) {
54+
std::vector<T> wiggleSort(const std::vector<T> &arr) {
5455
uint32_t size = arr.size();
5556

5657
std::vector<T> out(

0 commit comments

Comments
 (0)