-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush_swap_utils.c
More file actions
73 lines (67 loc) · 1.77 KB
/
push_swap_utils.c
File metadata and controls
73 lines (67 loc) · 1.77 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: opopov <opopov@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/14 15:58:42 by opopov #+# #+# */
/* Updated: 2025/03/26 10:40:42 by opopov ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_stack *find_last(t_stack *find)
{
if (find == NULL)
return (NULL);
while (find->next != NULL)
find = find->next;
return (find);
}
t_stack *find_highest(t_stack *find)
{
if (find == NULL)
return (NULL);
t_stack *buff = find;
t_stack *highest = find;
while (buff)
{
if (buff->value > highest->value)
highest = buff;
buff = buff->next;
}
return (highest);
}
t_stack *find_smallest(t_stack *find)
{
if (find == NULL)
return (NULL);
t_stack *buff = find;
t_stack *smallest = find;
while (buff)
{
if (buff->value < smallest->value)
smallest = buff;
buff = buff->next;
}
return (smallest);
}
void index_counter (t_stack *st)
{
int i;
int medium;
if (st == NULL)
return ;
medium = count_stacks(st) / 2;
i = 0;
while (st)
{
st->index = i;
if (i < medium)
st->is_below_medium = 0;
else
st->is_below_medium = 1;
st = st->next;
i++;
}
}