-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_swap.c
76 lines (68 loc) · 1.94 KB
/
push_swap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yrhiba <yrhiba@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/08 14:38:30 by yrhiba #+# #+# */
/* Updated: 2023/01/24 02:32:23 by yrhiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void quick_sort(t_push_swap *stacks)
{
t_data *front;
t_data *second;
front = ((t_data *)my_list_front(stacks->stack_a));
second = ((t_data *)my_list_get(stacks->stack_a, 1));
if (front->data > second->data)
{
sa(stacks);
ft_printf("sa\n");
}
}
static void three_sort(t_push_swap *stacks)
{
t_data *max;
max = get_max_data(stacks->stack_a);
if (max->cur_pos == 0)
{
ra(stacks);
ft_printf("ra\n");
}
else if (max->cur_pos == 1)
{
rra(stacks);
ft_printf("rra\n");
}
quick_sort(stacks);
}
void push_swap(t_push_swap *stacks)
{
init_floor(stacks);
if (stacks->size_a == 2)
{
quick_sort(stacks);
return ;
}
if (stacks->size_a == 3)
{
three_sort(stacks);
return ;
}
floor_one(stacks);
floor_two(stacks);
end_floor(stacks);
}
int main(int ac, char **av)
{
t_push_swap *stacks;
if (ac == 1)
return (0);
if (staks_init(&stacks) == -1)
return (ft_printf("Error\n"), 0);
if (check_argv(ac, av, stacks) == -1)
return (ft_printf("Error\n"), ps_clear(stacks), 0);
return (push_swap(stacks), ps_clear(stacks), 0);
}