-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexing.c
58 lines (53 loc) · 1.48 KB
/
indexing.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
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* indexing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lstorey <lstorey@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/21 11:15:57 by lstorey #+# #+# */
/* Updated: 2024/03/26 12:40:13 by lstorey ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_ps_list *find_min(t_ps_list **stack)
{
t_ps_list *tmp;
t_ps_list *min;
tmp = (*stack);
min = (*stack);
while (tmp)
{
if (min->index != -1 && min->next)
{
min = min->next;
}
if (tmp->number < min->number && tmp->index == -1)
{
min = tmp;
}
tmp = tmp->next;
}
return (min);
}
void adding_index(t_ps_list **stack)
{
t_ps_list *tmp;
t_ps_list *count;
int i;
int c;
i = 0;
c = 0;
count = *stack;
tmp = find_min(stack);
while ((count)->next != NULL)
{
count = count->next;
c++;
}
while (i <= c)
{
tmp->index = i++;
tmp = find_min(stack);
}
}