-
Notifications
You must be signed in to change notification settings - Fork 0
/
lis_utils.c
78 lines (71 loc) · 1.73 KB
/
lis_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
77
78
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lis_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ltombell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/06 11:33:24 by ltombell #+# #+# */
/* Updated: 2022/12/12 11:34:07 by ltombell ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_lis_finder(t_lista *lista, t_prg *prg)
{
t_lista *tmp;
int tmpnb;
int count;
prg->max_count = 0;
tmp = lista;
count = 1;
tmpnb = tmp->nb;
while (tmp)
{
if (tmpnb < tmp->nb)
{
tmpnb = tmp->nb;
count++;
}
tmp = tmp->next;
}
if (count > prg->max_count)
{
prg->max_count = count;
prg->best_lis = lista->nb;
}
}
int ft_doing_ra_counter(t_lista *lista, int nb)
{
int i;
i = 0;
while (lista->nb != nb && lista->next)
{
lista = lista->next;
i++;
}
if (lista->nb == nb)
return (i);
else
return (9999);
}
int ft_doing_rra_counter(t_lista *lista, int nb)
{
int i;
t_lista *tmp;
tmp = ft_list_last(lista);
i = 0;
while (lista->nb != nb && lista->prev)
{
lista = lista->prev;
i++;
}
if (lista->nb == nb)
{
return (i);
}
else
{
i += ft_doing_rra_counter(tmp, nb) + 1;
return (i);
}
}