blob: 4aa51b0553eabe3f900507236ba0d8e3f43144a9 (
plain)
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
41
42
43
44
45
46
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_int_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/03 18:06:03 by cacharle #+# #+# */
/* Updated: 2019/07/04 06:52:49 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
int is_sorted(int *tab, int size)
{
int i;
i = 0;
while (i < size - 1)
{
if (tab[i] > tab[i + 1])
return (0);
i++;
}
return (1);
}
void ft_sort_int_tab(int *tab, int size)
{
int i;
int tmp;
while (!is_sorted(tab, size))
{
i = 0;
while (i < size - 1)
{
if (tab[i] > tab[i + 1])
{
tmp = tab[i];
tab[i] = tab[i + 1];
tab[i + 1] = tmp;
}
i++;
}
}
}
|