-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_sort_small.c
More file actions
47 lines (43 loc) · 1.13 KB
/
Copy pathft_sort_small.c
File metadata and controls
47 lines (43 loc) · 1.13 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
#include "libft.h"
#include "ft_push_swap.h"
static t_l ft_init_arr(t_list **stack_a, t_list **stack_b)
{
t_l arr;
arr.a1 = ft_atoi((*stack_a)->content);
arr.a2 = ft_atoi((*stack_a)->next->content);
arr.a3 = ft_atoi((ft_lstlast(*stack_a))->content);
if (ft_lstsize(*stack_b))
{
arr.b1 = ft_atoi((*stack_b)->content);
if (ft_lstsize(*stack_b) > 1)
arr.b2 = ft_atoi((*stack_b)->next->content);
else
arr.b2 = 0;
}
return (arr);
}
void ft_sort_small(t_list **stack_a, t_list **stack_b)
{
t_l arr;
while ((ft_check_order_ascen(*stack_a) || ft_check_order_desc(*stack_b))
|| ft_lstsize(*stack_b))
{
arr = ft_init_arr(stack_a, stack_b);
if (!ft_check_order_ascen(*stack_a) && !ft_check_order_desc(*stack_b))
ft_pusha(stack_a, stack_b);
else
{
if (arr.a1 > arr.a2 && arr.a1 > arr.a3)
ft_rotatea(stack_a);
else if (arr.a1 > arr.a2 && arr.a1 < arr.a3)
ft_swapa(stack_a);
else if (arr.a1 < arr.a2 && arr.a1 > arr.a3)
ft_rrotatea(stack_a);
else if (arr.a1 < arr.a2 && arr.a1 < arr.a3
&& *stack_b && arr.b1 > arr.a1)
ft_pusha(stack_a, stack_b);
else
ft_pushb(stack_a, stack_b);
}
}
}