-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.c
More file actions
64 lines (59 loc) · 1.84 KB
/
sort.c
File metadata and controls
64 lines (59 loc) · 1.84 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctacconi <ctacconi@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/25 16:23:04 by ctacconi #+# #+# */
/* Updated: 2024/04/25 16:23:12 by ctacconi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void sort_two(t_stack *a)
{
sa(a);
}
void sort_three(t_stack *a)
{
if (a->first->index == 2 && a->first->next->index == 1
&& a->first->next->next->index == 3)
sa(a);
else if (a->first->index == 3 && a->first->next->index == 2
&& a->first->next->next->index == 1)
{
sa(a);
rra(a);
}
else if (a->first->index == 3 && a->first->next->index == 1
&& a->first->next->next->index == 2)
ra(a);
else if (a->first->index == 1 && a->first->next->index == 3
&& a->first->next->next->index == 2)
{
sa(a);
ra(a);
}
else if (a->first->index == 2 && a->first->next->index == 3
&& a->first->next->next->index == 1)
rra(a);
}
void sort_four(t_stack *a, t_stack *b)
{
move_index_x_to_top_of_a(1, a);
pb(a, b);
assign_index(a);
sort_three(a);
pa(b, a);
}
void sort_five(t_stack *a, t_stack *b)
{
move_index_x_to_top_of_a(1, a);
pb(a, b);
move_index_x_to_top_of_a(2, a);
pb(a, b);
assign_index(a);
sort_three(a);
pa(b, a);
pa(b, a);
}