-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate.c
55 lines (45 loc) · 1.68 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abertran <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/23 16:42:41 by abertran #+# #+# */
/* Updated: 2023/03/09 12:58:17 by abertran ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
/* The top element of the stack is sent to the bottom. */
static void rotate(t_stack **stack)
{
t_stack *tmp;
t_stack *tail;
tmp = *stack;
*stack = (*stack)->next;
tail = get_bottom(*stack);
tmp->next = NULL;
tail->next = tmp;
}
/* Sends the top element of stack a to the bottom.
Prints "ra" to the standard output */
void do_ra(t_stack **stack_a)
{
rotate(stack_a);
ft_putstr("ra\n");
}
/* Sends the top element of stack b to the bottom.
Prints "rb" to the standard output. */
void do_rb(t_stack **stack_b)
{
rotate(stack_b);
ft_putstr("rb\n");
}
/* Sends the top element of both stack a and stack b to the bottom
of their stacks. Prints "rr" to the standard output. */
void do_rr(t_stack **stack_a, t_stack **stack_b)
{
rotate(stack_a);
rotate(stack_b);
ft_putstr("rr\n");
}