-
Notifications
You must be signed in to change notification settings - Fork 0
/
instruction2.c
63 lines (57 loc) · 1.65 KB
/
instruction2.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* instruction2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ebennamr <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/05 20:51:41 by ebennamr #+# #+# */
/* Updated: 2023/02/14 16:58:39 by ebennamr ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
void rrx(t_int2 *tab, char *str)
{
int i;
int tmp;
if (tab->len < 2)
return ;
tmp = tab->pt[tab->len - 1];
i = tab->len - 1;
while (i > 0)
{
tab->pt[i] = tab->pt[i - 1];
i--;
}
tab->pt[0] = tmp;
if (str != 0)
write(1, str, 4);
}
void rrr(t_data *data, char *str)
{
rrx(data->stack_a, 0);
rrx(data->stack_b, 0);
if (str != 0)
write(1, "rrr\n", 4);
}
void px(t_int2 *tab1, t_int2 *tab2, int max, char *str)
{
int i;
if (max <= tab2->len || tab1->len <= 0)
return ;
i = ++(tab2->len);
while (i-- > 0)
{
tab2->pt[i] = tab2->pt[i - 1];
}
tab2->pt[0] = tab1->pt[0];
i = -1;
while (++i < tab1->len - 1)
{
tab1->pt[i] = tab1->pt[i + 1];
}
tab1->pt[tab1->len - 1] = 0;
(tab1->len)--;
if (str != 0)
write(1, str, ft_strlen(str));
}