-
Notifications
You must be signed in to change notification settings - Fork 1
/
ps_functions1.c
60 lines (53 loc) · 910 Bytes
/
ps_functions1.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
#include "push_swap.h"
void sa(int *stack_a, t_ps *ps, int control)
{
int temp;
if (ps->bottom_a < 1)
return ;
temp = stack_a[0];
stack_a[0] = stack_a[1];
stack_a[1] = temp;
if (control == 1)
write(1, "sa\n", 3);
}
void ra(int *stack_a, t_ps *ps, int control)
{
int temp;
int i;
temp = stack_a[0];
i = 0;
while (i < ps->bottom_a)
{
stack_a[i] = stack_a[i + 1];
i++;
}
stack_a[i] = temp;
if (control == 1)
write(1, "ra\n", 3);
}
void rra(int *stack_a, t_ps *ps, int control)
{
int temp;
int i;
i = ps->bottom_a;
temp = stack_a[ps->bottom_a];
while (i > 0)
{
stack_a[i] = stack_a[i - 1];
i--;
}
stack_a[i] = temp;
if (control == 1)
write(1, "rra\n", 4);
}
void pb(int *stack_a, int *stack_b, t_ps *ps)
{
if (ps->bottom_a < 0)
return ;
ps->top_b--;
stack_b[ps->top_b] = stack_a[0];
stack_a[0] = 0;
ra(stack_a, ps, 0);
ps->bottom_a--;
write(1, "pb\n", 3);
}