-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate.c
More file actions
37 lines (34 loc) · 1.78 KB
/
Copy pathrotate.c
File metadata and controls
37 lines (34 loc) · 1.78 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: caide-so <caide-so@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 20:02:07 by caide-so #+# #+# */
/* Updated: 2025/02/24 20:22:49 by caide-so ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
// Simultaneously rotates both stacks until target nodes reach top positions,
// optimizing move efficiency
// 1. Perform concurrent rotations while both stacks need adjustment
// 2. Update positional metadata after rotations complete
void rotate_both(t_stack **a, t_stack **b, t_stack *cheapest_node)
{
while ((*a) != cheapest_node && (*b) != cheapest_node->target)
rotate_ab(a, b, 1);
current_index(*a);
current_index(*b);
}
// Simultaneously reverse-rotates both stacks until target nodes reach
// top positions, optimizing for bottom-half element movement
// 1. Perform concurrent reverse rotations until targets are positioned
// 2. Update positional metadata after rotations complete
void reverse_rotate_both(t_stack **a, t_stack **b, t_stack *cheapest_node)
{
while ((*a) != cheapest_node && (*b) != cheapest_node->target)
reverse_rotate_ab(a, b, 1);
current_index(*a);
current_index(*b);
}