-
Notifications
You must be signed in to change notification settings - Fork 2
/
order_two.c
89 lines (79 loc) · 2.13 KB
/
order_two.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* order_two.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcerchi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/26 14:49:08 by mcerchi #+# #+# */
/* Updated: 2022/02/26 14:49:40 by mcerchi ### ########.fr */
/* */
/* ************************************************************************** */
#include "./libft/libft.h"
#include "push_swap.h"
int ft_the_needed(int min, int max, int size)
{
int i;
if (min > (size / 2))
min = min - size;
if (max > (size / 2))
max = max - size;
i = ft_min_nbr(max, min);
return (i);
}
int ft_the_needed_b(int max, int size)
{
if (max > (size / 2))
max = max - size;
return (max);
}
int ft_the_needed_a(t_list *stack_a, int cont, int size)
{
t_list *tmp;
int i;
tmp = stack_a;
i = ft_max_or_min(stack_a, cont, size);
if (i != size + 1)
return (ft_the_needed_b(i, size));
while (tmp->next != NULL)
tmp = tmp->next;
if (cont < stack_a->content && cont > tmp->content)
return (0);
i = 1;
while (!(cont > stack_a->content && cont < (stack_a->next)->content))
{
stack_a = stack_a->next;
i++;
}
return (ft_the_needed_b(i, size));
}
int *ft_copy_cont(t_list *stack_a, int size)
{
int *arr;
int i;
i = 0;
arr = (int *) malloc (sizeof(int) * size + 1);
if (!arr)
ft_display_exit();
while (stack_a != NULL)
{
arr[i++] = (stack_a)->content;
stack_a = (stack_a)->next;
}
return (arr);
}
int *ft_intcpy(int *arr, int size)
{
int i;
int *cpy;
i = 0;
cpy = (int *) malloc (sizeof(int) * size);
if (!arr || !cpy)
ft_display_exit();
while (i < size)
{
cpy[i] = arr[i];
i++;
}
return (cpy);
}