-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_sequence_next_sp.c
59 lines (55 loc) · 1.6 KB
/
find_sequence_next_sp.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: enoye <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/13 10:12:37 by enoye #+# #+# */
/* Updated: 2021/10/17 10:10:35 by enoye ### ########.fr */
/* */
/* ************************************************************************** */
#include "libpushswap.h"
static t_need help_again(t_list **b, t_need nd, t_list *limit, int i)
{
nd.toend = *b;
while (nd.toend != limit)
{
nd.nxt = nd.toend;
nd.finder = nd.nxt;
i = 0;
while (nd.finder != 0)
{
nd.nxt = nd.finder;
nd.finder = find_next_sp(nd.nxt, limit, nd.nxt, nd.sort);
i++;
}
if (i > nd.nofseq)
{
nd.qmax = nd.toend;
nd.qnext = nd.nxt;
nd.nofseq = i;
}
nd.toend = nd.toend -> next;
}
return (nd);
}
t_need find_sequence_next_sp(t_list **b, t_need nd)
{
t_list *limit;
int i;
limit = *b;
i = nd.diapazon;
while (i != 0 && limit != 0)
{
limit = limit -> next;
i--;
}
nd = help_again(b, nd, limit, i);
if (limit == *b)
{
nd.qmax = *b;
nd.qnext = *b;
}
return (nd);
}