-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_three.c
62 lines (55 loc) · 1.91 KB
/
sort_three.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort_three.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amezioun <amezioun@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/07 12:38:20 by amezioun #+# #+# */
/* Updated: 2024/06/07 13:37:02 by amezioun ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void case_one(t_stack **stack)
{
t_stack *tmp;
tmp = *stack;
if (tmp->content > tmp->next->content
&& tmp->next->content < tmp->next->next->content
&& !(tmp->next->next->content < tmp->content))
sa(&*stack);
}
void case_two(t_stack **stack)
{
t_stack *tmp;
tmp = *stack;
if (tmp->content < tmp->next->content
&& tmp->content > tmp->next->next->content
&& tmp->next->content > tmp->content
&& tmp->next->content > tmp->next->next->content)
rra(&*stack);
}
void sort_three(t_stack **stack)
{
t_stack *tmp;
tmp = *stack;
case_one(stack);
if (tmp->content > tmp->next->content
&& tmp->next->content > tmp->next->next->content)
{
sa(&*stack);
rra(&*stack);
}
else if (tmp->content > tmp->next->content
&& tmp->content > tmp->next->next->content
&& tmp->next->content < tmp->next->next->content)
ra(&*stack);
else if (tmp->next->content > tmp->content
&& tmp->next->content > tmp->next->next->content
&& tmp->content < tmp->next->next->content)
{
sa(&*stack);
ra(&*stack);
}
case_two(stack);
}