-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomizing_stack_b.c
53 lines (48 loc) · 1.69 KB
/
customizing_stack_b.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* customizing_stack_b.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dolvin17 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 23:48:57 by ghuertas #+# #+# */
/* Updated: 2023/12/11 19:16:47 by dolvin17 ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void set_target_b(t_stack *stack_a, t_stack *stack_b)
{
t_stack *node_a;
t_stack *target_b;
long closest_big;
while (stack_b)
{
closest_big = LONG_MAX;
node_a = stack_a;
while (node_a)
{
if (node_a->data > stack_b->data && node_a->data < closest_big)
{
closest_big = node_a->data;
target_b = node_a;
}
node_a = node_a->next;
}
if (closest_big == LONG_MAX)
stack_b->target = min_value(stack_a);
else
stack_b->target = target_b;
stack_b = stack_b->next;
}
}
void customizing_stack_b(t_stack *stack_a, t_stack *stack_b)
{
set_and_check_pos(stack_a);
set_and_check_pos(stack_b);
set_target_b(stack_a, stack_b);
}
void push_back_stack_a(t_stack **stack_a, t_stack **stack_b)
{
ready_to_push(stack_a, (*stack_b)->target, 'a');
ft_push("pa\n", stack_a, stack_b);
}