-
Notifications
You must be signed in to change notification settings - Fork 0
/
algo_for_5.c
35 lines (32 loc) · 1.47 KB
/
algo_for_5.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo_for_5.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/06/15 18:35:08 by earnaud #+# #+# */
/* Updated: 2021/07/16 15:42:41 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void algo_for_5(t_stacks *stack)
{
long min_max[2];
if (check_sorted(stack))
return ;
find_min_max(stack->a, min_max);
while (stack->a[stack_nb(stack->a)] != min_max[0])
best_rotate_a(stack, stack_nb(stack->a), min_max[0]);
switch_pb(stack, 1);
find_min_max(stack->a, min_max);
while (stack->a[stack_nb(stack->a)] != min_max[0])
best_rotate_a(stack, stack_nb(stack->a), min_max[0]);
switch_pb(stack, 1);
while (stack->a[0] != min_max[1])
best_rotate_a(stack, 0, min_max[1]);
if (stack->a[2] > stack->a[1])
switch_sa(stack, 1);
switch_pa(stack, 1);
switch_pa(stack, 1);
}