-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate.c
56 lines (50 loc) · 1.58 KB
/
rotate.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: stigkas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 14:16:01 by stigkas #+# #+# */
/* Updated: 2024/02/08 17:08:32 by stigkas ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/push_swap.h"
static int rotate(t_stack **stack)
{
t_stack *head;
t_stack *last;
if (!(*stack) || ft_stack_size(*stack) <= 1)
return (-1);
head = *stack;
last = ft_stacklast(head);
*stack = head->next;
head->next = NULL;
last->next = head;
return (0);
}
void ra(t_stack **stack_a)
{
if (rotate(stack_a) == -1)
ft_error("Error\n");
else
write(1, &"ra\n", 3);
}
void rb(t_stack **stack_b)
{
if (rotate(stack_b) == -1)
ft_error("Error\n");
else
write(1, &"rb\n", 3);
}
void rr(t_stack **stack_a, t_stack **stack_b)
{
if (ft_stack_size(*stack_a) <= 1 || ft_stack_size(*stack_b) <= 1)
ft_error("Error\n");
else
{
rotate(stack_a);
rotate(stack_b);
write(1, &"rr\n", 3);
}
}