-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_utils2.c
81 lines (72 loc) · 1.96 KB
/
stack_utils2.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
77
78
79
80
81
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amacarul <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 14:15:00 by amacarul #+# #+# */
/* Updated: 2024/10/17 17:01:37 by amacarul ### ########.fr */
/* */
/* ************************************************************************** */
#include "libpush_swap.h"
//Find min value
int get_min_value(t_stack *stack)
{
t_node *current;
t_node *min;
current = stack->top;
min = stack->top;
while (current != NULL)
{
if (current->val < min->val)
min = current;
current = current->next;
}
return (min->val);
}
//Find max value
int get_max_value(t_stack *stack)
{
t_node *current;
t_node *max;
current = stack->top;
max = stack->top;
while (current != NULL)
{
if (current->val > max->val)
max = current;
current = current->next;
}
return (max->val);
}
//Find min value pos
t_node *get_min_value_node(t_stack *stack)
{
t_node *current;
t_node *min_node;
current = stack->top;
min_node = current;
while (current != NULL)
{
if (current->val < min_node->val)
min_node = current;
current = current->next;
}
return (min_node);
}
//Find max value pos
t_node *get_max_value_node(t_stack *stack)
{
t_node *current;
t_node *max_node;
current = stack->top;
max_node = current;
while (current != NULL)
{
if (current->val > max_node->val)
max_node = current;
current = current->next;
}
return (max_node);
}