-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs2.c
65 lines (58 loc) · 1.89 KB
/
funcs2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* funcs2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tle-meur <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/12 14:00:40 by tle-meur #+# #+# */
/* Updated: 2016/01/14 14:51:50 by tle-meur ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int my_rrx(int *pile, int size)
{
int i;
int tmp;
i = 0;
tmp = pile[i];
while (i < size - 1)
{
pile[i] = pile[i + 1];
i++;
}
pile[i] = tmp;
return (1);
}
int my_rrr(int *pile1, int *pile2, int size1, int size2)
{
return (my_rrx(pile1, size1) && my_rrx(pile2, size2));
}
int my_swap(int *pile, int size, int sens)
{
if (size < 2)
return (0);
if (sens < 0)
return (size && pile[size - 2] > pile[size - 1]);
else
return (size && pile[size - 2] < pile[size - 1]);
}
int my_reverse(int *pile, int size, int sens)
{
if (size < 2)
return (0);
if (sens < 0)
return (pile[size - 1] < pile[0] && (size == 2 || pile[1] < pile[0]));
else
return ((pile[size - 1] < pile[0] || pile[size - 1] > pile[0])
&& (size == 2 || pile[1] > pile[0]));
}
int my_rotate(int *pile, int size, int sens)
{
if (size < 2)
return (0);
if (sens < 0)
return (pile[size - 1] < pile[0] && (size == 2 || pile[1] > pile[0]));
else
return (pile[size - 1] > pile[0] && (size == 2 || pile[1] < pile[0]));
}