-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_sort.c
69 lines (62 loc) · 1.8 KB
/
select_sort.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* select_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/07 15:47:15 by jjacobso #+# #+# */
/* Updated: 2019/02/08 19:18:31 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void go_to_swap(t_stacks_state *arg)
{
int min;
int max;
min = l_int_min(arg->a);
max = l_int_max(arg->a);
if ((l_int_positon(arg->a, min)) < l_size(arg->a) / 2)
while (DATA(arg->a) != min && DATA(arg->a) != max)
RRA;
else
while (DATA(arg->a) != min && DATA(arg->a) != max)
RA;
}
static void spinn_back(t_stacks_state *arg)
{
int max;
max = l_int_max(arg->b);
if ((l_int_positon(arg->b, max)) < l_size(arg->b) / 2)
while (DATA(arg->b) != max)
RRB;
else
while (DATA(arg->b) != max)
RB;
}
void select_sort(t_stacks_state *arg)
{
int min;
min = INT_MAX;
while (arg->a)
if (l_size(arg->a) == 3)
{
sort3_a(arg, 3);
PB;
PB;
PB;
break ;
}
else if (DATA(arg->a) == (min = l_int_min(arg->a)))
PB;
else if (DATA(arg->a) == (l_int_max(arg->a)))
{
PB;
RB;
}
else
go_to_swap(arg);
spinn_back(arg);
while (arg->b)
PA;
}