-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
76 lines (68 loc) · 1.73 KB
/
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
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
74
75
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sanmetol <sanmetol@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/30 15:10:14 by sanmetol #+# #+# */
/* Updated: 2024/10/02 16:10:21 by sanmetol ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_node *return_cheapest(t_node *stack)
{
if (stack == NULL)
return (NULL);
while (stack)
{
if (stack->cheapest)
return (stack);
stack = stack->next;
}
return (NULL);
}
t_node *find_smallest(t_node *stack)
{
long smallest;
t_node *smallest_node;
if (stack == NULL)
return (NULL);
smallest = LONG_MAX;
while (stack)
{
if (stack->n < smallest)
{
smallest = stack->n;
smallest_node = stack;
}
stack = stack->next;
}
return (smallest_node);
}
int stack_size(t_node *stack)
{
int i;
if (stack == NULL)
return (0);
i = 0;
while (stack)
{
i++;
stack = stack->next;
}
return (i);
}
int all_spaces(const char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] != ' ' && str[i] != '\f' && str[i] != '\n'
&& str[i] != '\r' && str[i] != '\t' && str[i] != '\v')
return (0);
i++;
}
return (1);
}