-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotating.c
52 lines (45 loc) · 1.74 KB
/
rotating.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotating.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lstorey <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/19 09:54:40 by lstorey #+# #+# */
/* Updated: 2024/03/29 18:03:08 by lstorey ### ########.fr */
/* */
/* ************************************************************************** */
/* ************************************************************* */
/* ra - rotate stack A. shift up all elements by one */
/* rb - rotate stack B. shift up all elements by one */
/* rr - rotate stack A + B. shift up all elements by one */
/* ************************************************************* */
#include "push_swap.h"
static void rotate(t_ps_list **stack)
{
t_ps_list *top_node;
t_ps_list *bottom_node;
t_ps_list *second_node;
top_node = *stack;
bottom_node = find_last_node(*stack);
second_node = (*stack)->next;
bottom_node->next = top_node;
top_node->next = NULL;
*stack = second_node;
}
void ra(t_ps_list **stack_a)
{
rotate(stack_a);
ft_printf("ra\n");
}
void rb(t_ps_list **stack_b)
{
rotate(stack_b);
ft_printf("rb\n");
}
void rr(t_ps_list **stack_a, t_ps_list **stack_b)
{
rotate(stack_a);
rotate(stack_b);
ft_printf("rr\n");
}