-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminmax.c
108 lines (103 loc) · 2.38 KB
/
minmax.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* minmax.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fraqioui <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/13 08:00:03 by fraqioui #+# #+# */
/* Updated: 2022/12/13 08:00:05 by fraqioui ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
//returning the max data
int ft_max_data(t_node *trav, int len)
{
int max;
max = trav->next->data;
trav = trav->next->next;
while (--len)
{
if (max < trav->data)
max = trav->data;
trav = trav->next;
}
return (max);
}
//returning the min data
int ft_min_data(t_node *trav, int len)
{
int min;
min = trav->next->data;
trav = trav->next->next;
while (--len)
{
if (min > trav->data)
min = trav->data;
trav = trav->next;
}
return (min);
}
//returning the node that has the min data
t_node *ft_min_node(t_node *last, int len)
{
int min;
t_node *save;
if (!last)
return (NULL);
min = last->next->data;
save = last->next;
last = last->next->next;
while (--len)
{
if (min > last->data)
{
min = last->data;
save = last;
}
last = last->next;
}
return (save);
}
//returning the node that has the minimum moves
t_node *ft_min_n_moves(t_node *last, int len)
{
int min;
t_node *save;
if (!last)
return (NULL);
min = last->next->n_moves;
save = last->next;
last = last->next->next;
while (--len)
{
if (min > last->n_moves)
{
min = last->n_moves;
save = last;
}
last = last->next;
}
return (save);
}
//returning the node that has the max pos_a
t_node *ft_max_pos_a(t_node *last, int len)
{
int max;
t_node *save;
if (!last)
return (NULL);
max = last->next->n_moves;
save = last->next;
last = last->next->next;
while (--len)
{
if (max < last->pos_a)
{
max = last->pos_a;
save = last;
}
last = last->next;
}
return (save);
}