-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations2.c
69 lines (61 loc) · 1.82 KB
/
operations2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsosevic <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/09 12:44:43 by vsosevic #+# #+# */
/* Updated: 2017/03/09 12:45:37 by vsosevic ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void push_b(t_stack *a, t_stack *b, char **cmds)
{
if (a->nbrs_l > 0)
{
shift_down(b);
b->nbrs[0] = a->nbrs[0];
shift_up(a);
(*cmds) = ft_strjoin_m(*cmds, "pb\n");
}
}
void rotate_rx(t_stack *stk, char **cmds)
{
int tmp;
if (stk->nbrs_l > 1)
{
tmp = stk->nbrs[0];
shift_up(stk);
stk->nbrs[stk->nbrs_l++] = tmp;
if (stk->name == 'a')
(*cmds) = ft_strjoin_m(*cmds, "ra\n");
else
(*cmds) = ft_strjoin_m(*cmds, "rb\n");
}
}
void rotate_rr(t_stack *a, t_stack *b, char **cmds)
{
rotate_rx(a, cmds);
rotate_rx(b, cmds);
}
void rotate_rrx(t_stack *stk, char **cmds)
{
int tmp;
if (stk->nbrs_l > 1)
{
tmp = stk->nbrs[stk->nbrs_l - 1];
shift_down(stk);
stk->nbrs[0] = tmp;
stk->nbrs_l--;
if (stk->name == 'a')
(*cmds) = ft_strjoin_m(*cmds, "rra\n");
else
(*cmds) = ft_strjoin_m(*cmds, "rrb\n");
}
}
void rotate_rrr(t_stack *a, t_stack *b, char **cmds)
{
rotate_rrx(a, cmds);
rotate_rrx(b, cmds);
}