-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
91 lines (82 loc) · 1.98 KB
/
utils.c
File metadata and controls
91 lines (82 loc) · 1.98 KB
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
90
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: agallipo <agallipo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/13 20:28:31 by agallipo #+# #+# */
/* Updated: 2021/11/25 12:20:04 by agallipo ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void ft_while_ra(t_list **stack_a, int i)
{
while (i > 0)
{
ft_ra(stack_a);
i--;
}
}
static void ft_while_rra(t_list **stack_a, int i, int size)
{
while (i < size)
{
ft_rra(stack_a);
i++;
}
}
void ft_find_chk(t_list **stack_a, t_list **stack_b, int pos, t_chunk *chk)
{
t_list *temp;
int i;
int size;
temp = *stack_a;
i = 0;
size = ft_check_nums(stack_a);
while (ft_is_chunk(temp->content, chk->org, pos, chk->min) == 0)
{
i++;
temp = temp->next;
}
if (i < (size / 2))
ft_while_ra(stack_a, i);
else
ft_while_rra(stack_a, i, size);
ft_pb(stack_a, stack_b);
}
void ft_sort_int_tab(int *org, int size)
{
int i;
int j;
int temp;
i = 0;
while (i < size - 1)
{
j = 1;
while (j < size)
{
if (org[j] < org[j - 1])
{
temp = org[j];
org[j] = org[j - 1];
org[j - 1] = temp;
}
j++;
}
i++;
}
}
int ft_check_left(t_list **stack_a, int pos, t_chunk *chk)
{
t_list *temp;
temp = *stack_a;
while (temp)
{
if (temp->content >= chk->org[chk->min]
&& temp->content < chk->org[pos])
return (1);
temp = temp->next;
}
return (0);
}