-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.c
55 lines (50 loc) · 1.56 KB
/
arrays.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* arrays.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ltombell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 11:33:51 by ltombell #+# #+# */
/* Updated: 2022/12/12 11:33:58 by ltombell ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int *ft_create_mova_array(t_lista **a, t_lista **b, t_prg *prg)
{
int *res;
int i;
t_lista *tmplist;
i = 0;
tmplist = *b;
res = (int *)malloc(sizeof(int) * ft_list_length(*b));
while (*b)
{
res[i] = ft_find_best_move_ra(a, (*b)->nb, prg);
i++;
*b = (*b)->next;
}
*b = tmplist;
return (res);
}
int *ft_create_movb_array(t_lista **lista)
{
int *res;
int i;
int tmplen;
t_lista *tmplist;
tmplist = *lista;
i = 0;
res = (int *)malloc(sizeof(int) * ft_list_length(tmplist));
tmplen = ft_list_length(tmplist);
while (tmplist)
{
if (i < (tmplen / 2))
res[i] = i;
else
res[i] = (i - tmplen);
i++;
tmplist = tmplist->next;
}
return (res);
}