-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathps_functions2.c
60 lines (53 loc) · 999 Bytes
/
ps_functions2.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 sb(int *stack_b, t_ps *ps, int control)
{
int temp;
if (ps->size - ps->top_b < 2)
return ;
temp = stack_b[ps->top_b];
stack_b[ps->top_b] = stack_b[ps->top_b + 1];
stack_b[ps->top_b + 1] = temp;
if (control == 1)
write(1, "sb\n", 3);
}
void rb(int *stack_b, t_ps *ps, int control)
{
int temp;
int i;
if (ps->size - ps->top_b < 2)
return ;
temp = stack_b[ps->top_b];
i = ps->top_b;
while (i < ps->size - 1)
{
stack_b[i] = stack_b[i + 1];
i++;
}
stack_b[i] = temp;
if (control == 1)
write(1, "rb\n", 3);
}
void rrb(int *stack_b, t_ps *ps, int control)
{
int temp;
int i;
i = ps->size - 1;
temp = stack_b[ps->size - 1];
while (i > ps->top_b)
{
stack_b[i] = stack_b[i - 1];
i--;
}
stack_b[i] = temp;
if (control == 1)
write(1, "rrb\n", 4);
}
void pa(int *stack_b, int *stack_a, t_ps *ps)
{
ps->bottom_a++;
rra(stack_a, ps, 0);
stack_a[0] = stack_b[ps->top_b];
stack_b[ps->top_b] = 0;
ps->top_b++;
write(1, "pa\n", 3);
}