Skip to content

Commit c026e8c

Browse files
authored
Updated documentation in insertion_sort_recursive.cpp
1 parent ab76cac commit c026e8c

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

sorting/insertion_sort_recursive.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* @file
33
* @brief Insertion Sort Algorithm
4-
*
4+
* @author [Dhanush S] (https://github.com/Fandroid745)
5+
*
56
* @details
67
* Insertion sort is a simple sorting algorithm that builds the final
78
* sorted array one element at a time. It is much less efficient compared
@@ -16,18 +17,22 @@
1617
* Insertion sort works similarly to how people sort playing cards in their hands.
1718
* The algorithm iterates through the list and inserts each element into its correct
1819
* position in the sorted portion of the array.
19-
*
20+
*
21+
* The time complexity of the algorithm is \f$O(n^2)\f$, and in some cases, it
22+
* can be \f$O(n)\f$.
23+
*
2024
* Example execution:
2125
* 1. Start with the array [4, 3, 2, 5, 1].
2226
* 2. Insert 3 in its correct position: [3, 4, 2, 5, 1].
2327
* 3. Insert 2: [2, 3, 4, 5, 1].
2428
* 4. Continue this until the array is sorted: [1, 2, 3, 4, 5].
2529
*/
2630

27-
#include <algorithm> ///< for std::is_sorted
28-
#include <cassert> ///< for assert function in testing
29-
#include <iostream> ///< for std::cout and std::endl
30-
#include <vector> ///< for using std::vector
31+
32+
#include <algorithm> /// for std::is_sorted
33+
#include <cassert> /// for assert function in testing
34+
#include <iostream> /// for std::cout and std::endl
35+
#include <vector> /// for using std::vector
3136

3237
/**
3338
* @namespace sorting
@@ -39,7 +44,7 @@ namespace sorting {
3944
* @brief Insertion Sort Function
4045
*
4146
* @tparam T Type of the array elements
42-
* @param [in,out] arr Array to be sorted
47+
* @param[in,out] arr Array to be sorted
4348
* @param n Size of the array
4449
*/
4550
template <typename T>
@@ -96,7 +101,7 @@ static void create_random_array(T *arr, int N) {
96101
/**
97102
* @brief Test Cases for the sorting algorithm
98103
*/
99-
void tests() {
104+
static void tests() {
100105
int arr1[10] = {78, 34, 35, 6, 34, 56, 3, 56, 2, 4};
101106
std::cout << "Test 1... ";
102107
sorting::insertionSort(arr1, 10);
@@ -141,11 +146,11 @@ void tests() {
141146
*
142147
* Empty except for the call to `tests()`.
143148
*
144-
* @return 0 Always returns 0.
149+
* @return 0 on successful exit.
145150
*/
146151
int main() {
147152
/// Running predefined tests to test the algorithm
148-
tests();
153+
tests(); /// run self test implementations
149154

150155
return 0;
151156
}

0 commit comments

Comments
 (0)