-
Notifications
You must be signed in to change notification settings - Fork 1
/
rev_rotate.c
56 lines (49 loc) · 1.6 KB
/
rev_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rev_rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lburkins <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/16 14:11:22 by lburkins #+# #+# */
/* Updated: 2024/03/04 13:50:21 by lburkins ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void rev_rotate(t_node **stack)
{
t_node *last_node;
t_node *new_bottom;
if (!*stack || !(*stack)->next)
return ;
last_node = find_last_node(*stack);
new_bottom = last_node->prev;
new_bottom->next = NULL;
last_node->next = *stack;
last_node->prev = NULL;
last_node->next->prev = last_node;
*stack = last_node;
}
void rra(t_node **a)
{
rev_rotate(a);
ft_printf("rra\n");
}
void rrb(t_node **b)
{
rev_rotate(b);
ft_printf("rrb\n");
}
void rrr(t_node **a, t_node **b)
{
rev_rotate(a);
rev_rotate(b);
ft_printf("rrr\n");
}
void rev_rotate_both(t_node **a, t_node **b, t_node *cheapest)
{
while (*a != cheapest && *b != cheapest->target_node)
rrr(a, b);
current_index(*a);
current_index(*b);
}