Skip to content

Commit 04516c6

Browse files
committed
Update timsort.c to align with the contribution guidelines before creating a PR.
1 parent 58db283 commit 04516c6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

sorting/timsort.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
/**
22
* @file
3-
* @author [LJFP](https://github.com/ljfp/)
43
* @brief [Timsort](https://en.wikipedia.org/wiki/Timsort) implementation
54
* @details
65
* Timsort is a hybrid stable sorting algorithm, derived from merge sort and
76
* insertion sort, designed to perform well on many kinds of real-world data.
87
* Worst-case time complexity is O(n log n).
98
* Worst-case space complexity is O(n).
9+
* @author [LJFP](https://github.com/ljfp/)
10+
* @see merge_sort.c, insertion_sort.c
1011
*/
1112
#include <assert.h>
1213
#include <stdio.h>
1314
#include <stdlib.h>
1415
#include <time.h>
1516

1617
#define min(a, b) \
17-
((a) < (b) ? (a) : (b)) /* Macro to find the minimum of two numbers */
18+
((a) < (b) ? (a) : (b))
1819

1920
/**
2021
* @brief Performs insertion sort on a subarray
2122
* @param arr Array to be sorted
2223
* @param left Starting index of the subarray
2324
* @param right Ending index of the subarray
2425
*/
25-
void insertionSort(int arr[], int left, int right)
26+
void insertion_sort(int arr[], int left, int right)
2627
{
2728
for (int i = left + 1; i <= right; i++)
2829
{
@@ -97,7 +98,7 @@ void timsort(int arr[], int n, int run_size)
9798
/* Sort individual subarrays of size run_size */
9899
for (int i = 0; i < n; i += run_size)
99100
{
100-
insertionSort(arr, i, min((i + run_size - 1), (n - 1)));
101+
insertion_sort(arr, i, min((i + run_size - 1), (n - 1)));
101102
}
102103

103104
/* Start merging from size run_size */
@@ -133,7 +134,7 @@ void test()
133134
arr[i] = (rand() % 1000) - 500; /* Signed random numbers */
134135
}
135136

136-
/* Test with different run sizes */
137+
/* Test with different run sizes but always a power of 2 */
137138
for (int run_size = 16; run_size <= 64; run_size *= 2)
138139
{
139140
/* Copy the original array to preserve it for each run size */

0 commit comments

Comments
 (0)