-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate_command.c
More file actions
50 lines (44 loc) · 1.64 KB
/
Copy pathrotate_command.c
File metadata and controls
50 lines (44 loc) · 1.64 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate_command.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tbui-quo <tbui-quo@student.42wolfsburg.d> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/29 13:50:37 by tbui-quo #+# #+# */
/* Updated: 2023/09/29 13:50:37 by tbui-quo ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void rotate(t_stack **stack_x)
{
t_stack *first_element;
t_stack *second_element;
t_stack *new_first_element;
if (*stack_x == NULL || (*stack_x)->next == NULL)
return ;
first_element = *stack_x;
second_element = first_element->next;
new_first_element = second_element;
first_element->next = NULL;
while (second_element->next != NULL)
second_element = second_element->next;
second_element->next = first_element;
*stack_x = new_first_element;
}
void ra(t_stack **stack_a)
{
rotate(stack_a);
ft_putstr_fd("ra\n", STDOUT_FILENO);
}
void rb(t_stack **stack_b)
{
rotate(stack_b);
ft_putstr_fd("rb\n", STDOUT_FILENO);
}
void rr(t_stack **stack_a, t_stack **stack_b)
{
rotate(stack_a);
rotate(stack_b);
ft_putstr_fd("rr\n", STDOUT_FILENO);
}