-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransactions_ab.c
73 lines (66 loc) · 1.7 KB
/
transactions_ab.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
70
71
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* transactions_ab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: deryacar <deryacar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 19:34:58 by deryacar #+# #+# */
/* Updated: 2023/12/01 19:37:09 by deryacar ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <unistd.h>
void ss(t_stack *s, int print)
{
int tmp;
tmp = 0;
tmp = s->a[0];
s->a[0] = s->a[1];
s->a[1] = tmp;
tmp = s->b[0];
s->b[0] = s->b[1];
s->b[1] = tmp;
if (!print)
write(1, "ss\n", 3);
}
void rr(t_stack *s, int print)
{
int tmp;
int i;
i = 0;
tmp = s->a[i];
while (++i < s->size_a)
s->a[i - 1] = s->a[i];
s->a[i - 1] = tmp;
i = 0;
tmp = s->b[i];
while (++i < s->size_b)
s->b[i - 1] = s->b[i];
s->b[i - 1] = tmp;
if (!print)
write(1, "rr\n", 3);
}
void rrr(t_stack *s, int print)
{
int tmp;
int i;
if (s->size_b > 0)
{
i = s->size_a - 1;
tmp = s->a[i];
while (i)
{
s->a[i] = s->a[i - 1];
i--;
}
s->a[i] = tmp;
i = s->size_b - 1;
tmp = s->b[i];
while (i--)
s->b[i] = s->b[i - 1];
s->b[i] = tmp;
if (!print)
write(1, "rrr\n", 4);
}
}