-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_utils.c
42 lines (38 loc) · 1.36 KB
/
ft_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfrank <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/28 16:54:11 by lfrank #+# #+# */
/* Updated: 2023/03/13 15:16:04 by lfrank ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_put_index(t_node **first_node, int size)
{
t_node *smallest_node;
t_node *tmp;
int index;
int smallest;
index = 0;
tmp = *first_node;
while (index < size)
{
smallest = INT_MAX;
tmp = *first_node;
while (tmp != NULL)
{
if (tmp->number < smallest && tmp->has_index == false)
{
smallest_node = tmp;
smallest = tmp->number;
}
tmp = tmp->next;
}
smallest_node->index = index;
smallest_node->has_index = true;
index++;
}
}