-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_shell_sort.c
40 lines (38 loc) · 1.21 KB
/
ft_shell_sort.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_shell_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sebasnadu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 10:00:31 by sebasnadu #+# #+# */
/* Updated: 2024/02/09 12:57:10 by sebasnadu ### ########.fr */
/* */
/* ************************************************************************** */
void ft_shell_sort(int *nbrs, int len)
{
int gap;
int tmp;
int i;
int j;
if (len < 2 || !nbrs)
return ;
gap = len / 2;
while (gap > 0)
{
i = gap;
while (i < len)
{
tmp = nbrs[i];
j = i;
while (j >= gap && nbrs[j - gap] > tmp)
{
nbrs[j] = nbrs[j - gap];
j -= gap;
}
nbrs[j] = tmp;
++i;
}
gap /= 2;
}
}