-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse_rotate.c
57 lines (47 loc) · 1.77 KB
/
reverse_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
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* reverse_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abertran <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/23 18:24:22 by abertran #+# #+# */
/* Updated: 2023/02/23 18:44:03 by abertran ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
/* Brings the bottom element of a stack to the top. */
static void rev_rotate(t_stack **stack)
{
t_stack *tmp;
t_stack *tail;
t_stack *new_tail;
tail = get_bottom(*stack);
new_tail = before_bottom(*stack);
tmp = *stack;
*stack = tail;
(*stack)->next = tmp;
new_tail->next = NULL;
}
/* Brings the bottom element of stack a to the top.
Prints "rra" to the standard output. */
void do_rra(t_stack **stack_a)
{
rev_rotate(stack_a);
ft_putstr("rra\n");
}
/* Brings the bottom element of stack b to the top.
Prints "rrb" to the standard output. */
void do_rrb(t_stack **stack_b)
{
rev_rotate(stack_b);
ft_putstr("rrb\n");
}
/* Brings the bottom element of both stack a and stack be to the top of
their stacks. Prints "rrr" to the standard output. */
void do_rrr(t_stack **stack_a, t_stack **stack_b)
{
rev_rotate(stack_a);
rev_rotate(stack_b);
ft_putstr("rrr\n");
}