-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations2.c
72 lines (62 loc) · 1.9 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
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* operations2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: earnaud <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/16 16:40:46 by earnaud #+# #+# */
/* Updated: 2021/07/22 17:26:00 by earnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void switch_ss(t_stacks *stack)
{
write(STDOUT_FILENO, "ss\n", 3);
switch_sa(stack, 0);
switch_sb(stack, 0);
}
void switch_sb(t_stacks *stack, int write_it)
{
long temp;
if (write_it)
write(STDOUT_FILENO, "sb\n", 3);
if (stack_nb(stack->b) <= 1)
return ;
temp = stack->b[stack_nb(stack->b)];
stack->b[stack_nb(stack->b)] = stack->b[stack_nb(stack->b) - 1];
stack->b[stack_nb(stack->b) - 1] = temp;
}
void switch_sa(t_stacks *stack, int write_it)
{
long temp;
if (write_it)
write(STDOUT_FILENO, "sa\n", 3);
if (stack_nb(stack->a) <= 1)
return ;
temp = stack->a[stack_nb(stack->a)];
stack->a[stack_nb(stack->a)] = stack->a[stack_nb(stack->a) - 1];
stack->a[stack_nb(stack->a) - 1] = temp;
}
int stack_size(long *stack)
{
int i;
i = 0;
if (!stack)
return (0);
while (stack[i] != END_STACK)
i++;
return (i);
}
int stack_nb(long *stack)
{
int i;
i = 0;
while (stack[i] != END_STACK)
i++;
if (stack[i] == END_STACK && i)
i--;
if (stack[i] == END_STACK)
return (-1);
return (i);
}