-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_helpers.c
56 lines (51 loc) · 1.45 KB
/
sort_helpers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort_helpers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmaliare <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/20 12:06:49 by nmaliare #+# #+# */
/* Updated: 2023/02/20 12:09:41 by nmaliare ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int check_if_sorted(t_dlist **a, t_data *astart)
{
int i;
i = 0;
*a = astart->head;
if (astart->len > 0)
{
while (++i + 1 <= astart->len)
{
if ((*a)->num > (*a)->next->num)
return (0);
*a = (*a)->next;
}
}
return (1);
}
void sort_cpy(t_dlist **a, t_data *start)
{
int i;
int tmp;
i = 1;
*a = start->head;
while ((i + 1) <= start->len)
{
if ((*a)->num > (*a)->next->num)
{
tmp = (*a)->num;
(*a)->num = (*a)->next->num;
(*a)->next->num = tmp;
i = 1;
*a = start->head;
}
else
{
i++;
*a = (*a)->next;
}
}
}