-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheapest_number.c
39 lines (36 loc) · 1.29 KB
/
cheapest_number.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cheapest_number.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmatjuhi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 13:42:54 by kmatjuhi #+# #+# */
/* Updated: 2024/01/19 12:59:38 by kmatjuhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int cheapest_number(t_stack **a, t_stack **b)
{
t_stack *temp;
int moves;
int min_moves;
int min_pos;
int count;
count = count_nodes(*b);
min_moves = 600;
temp = *b;
while (count--)
{
moves = count_moves(a, b, temp->pos);
if (moves < min_moves)
{
min_moves = moves;
min_pos = temp->pos;
if (min_moves < 2)
return (min_pos);
}
temp = temp->next;
}
return (min_pos);
}