-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo_for_3.c
44 lines (40 loc) · 1.41 KB
/
algo_for_3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo_for_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/15 15:40:26 by earnaud #+# #+# */
/* Updated: 2021/07/22 16:14:26 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void algo_for_2(t_stacks *stack)
{
if (stack->a[0] > stack->a[1])
return ;
else
switch_ra(stack, 1);
}
void algo_for_3(t_stacks *stack)
{
long min_max[2];
if (check_sorted(stack))
return ;
find_min_max(stack->a, min_max);
if (stack->a[2] == min_max[1])
{
switch_ra(stack, 1);
if (!check_sorted(stack))
switch_sa(stack, 1);
}
else if (stack->a[1] == min_max[1])
{
switch_rra(stack, 1);
if (!check_sorted(stack))
switch_sa(stack, 1);
}
else if (stack->a[0] == min_max[1])
switch_sa(stack, 1);
}