-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_utils3.c
More file actions
74 lines (65 loc) · 1.6 KB
/
list_utils3.c
File metadata and controls
74 lines (65 loc) · 1.6 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
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_utils3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yaqliu <yaqliu@student.42barcelona.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/08 22:47:35 by yaqliu #+# #+# */
/* Updated: 2026/02/12 00:54:36 by yaqliu ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
int get_min(t_stack *a)
{
int min;
min = a->value;
while (a)
{
if (a->value < min)
min = a->value;
a = a->next;
}
return (min);
}
t_stack *lstlast(t_stack *stack)
{
if (!stack)
return (NULL);
while (stack -> next)
stack = stack -> next;
return (stack);
}
void ft_clear(t_stack **stack)
{
t_stack *tmp;
if (!stack || !(*stack))
return ;
while (*stack)
{
tmp = (*stack)->next;
free(*stack);
*stack = tmp;
}
*stack = NULL;
}
void ft_clean_all(t_stack **a, t_stack **b)
{
ft_clear(a);
ft_clear(b);
}
int get_position(t_stack *s, int val)
{
t_stack *tmp;
int i;
i = 0;
tmp = s;
while (tmp)
{
if (tmp->r_pos == val)
return (i);
tmp = tmp->next;
i++;
}
return (-1);
}