-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_2.c
49 lines (45 loc) · 927 Bytes
/
handler_2.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
#include "push_swap.h"
void parallel_rotate(t_stack *a, t_stack *b, t_elem *b_min)
{
char *stack_name;
size_t i;
t_stack *stack_to_move;
i = 0;
while (i++ < min(b_min->op_cnt[0], b_min->op_cnt[1]))
r_rotate(a, b);
if (b_min->op_cnt[0] > b_min->op_cnt[1])
{
stack_to_move = b;
stack_name = "b";
}
else
{
stack_to_move = a;
stack_name = "a";
}
i--;
while (i++ < max(b_min->op_cnt[0], b_min->op_cnt[1]))
rotate(stack_to_move, stack_name);
}
void parallel_rev_rotate(t_stack *a, t_stack *b, t_elem *b_min)
{
char *stack_name;
size_t i;
t_stack *stack_to_move;
i = 0;
while (i++ < min(b_min->op_cnt[0], b_min->op_cnt[1]))
r_reverse_rotate(a, b);
if (b_min->op_cnt[0] > b_min->op_cnt[1])
{
stack_to_move = b;
stack_name = "b";
}
else
{
stack_to_move = a;
stack_name = "a";
}
i--;
while (i++ < max(b_min->op_cnt[0], b_min->op_cnt[1]))
reverse_rotate(stack_to_move, stack_name);
}