-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_arr.c
58 lines (53 loc) · 1.42 KB
/
sort_arr.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: enoye <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/13 10:12:37 by enoye #+# #+# */
/* Updated: 2021/10/17 10:10:35 by enoye ### ########.fr */
/* */
/* ************************************************************************** */
#include "libpushswap.h"
static int are_you_sorted(int *arr, int l)
{
int *current;
int *next;
current = arr;
next = arr + 1;
while (l - 1 != 0)
{
if (*current > *next)
return (0);
current++;
next++;
l--;
}
return (1);
}
void sort_arr(int *arr, int l)
{
int *current;
int *next;
int tmp;
int x;
while (are_you_sorted(arr, l) == 0)
{
x = l;
current = arr;
next = arr + 1;
while (x - 1 != 0)
{
if (*current > *next)
{
tmp = *next;
*next = *current;
*current = tmp;
}
x--;
current++;
next++;
}
}
}