-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotate.c
54 lines (50 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: brulutaj <brulutaj@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 17:02:46 by brulutaj #+# #+# */
/* Updated: 2024/05/02 17:38:54 by brulutaj ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void rotate_op(t_dll **stack)
{
t_dll *head;
t_dll *last;
t_dll *second;
if (dll_size(*stack) == 1)
return ;
head = *stack;
last = dll_last(head);
second = head->next;
head->prev = last;
head->next = NULL;
last->next = head;
second->prev = NULL;
*stack = second;
set_index(stack);
}
void rotate(t_dll **stack_a, t_dll **stack_b, int flag)
{
if (flag == MOVE_A)
{
rotate_op(stack_a);
write(1, "ra\n", 3);
return ;
}
else if (flag == MOVE_B)
{
rotate_op(stack_b);
write(1, "rb\n", 3);
return ;
}
else if (flag == MOVE_BOTH)
{
rotate_op(stack_a);
rotate_op(stack_b);
}
write(1, "rr\n", 3);
}