Files
42-Push_Swap/flags/algorithms_sort.c
Maoake Teriierooiterai 00af75f98f fix algo
2026-01-14 11:59:30 +01:00

67 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algorithms_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 12:15:02 by mteriier #+# #+# */
/* Updated: 2026/01/08 16:07:00 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "medium_headers.h"
#include "parsing.h"
void simple(t_stacks *stacks)
{
int len;
len = stack_a_len(stacks);
insertion(stacks, len);
}
void medium(t_stacks *stacks)
{
t_tab *buckets;
int range;
int len;
len = stack_a_len(stacks);
if (len == 2)
sort_two(stacks);
else
{
range = range_bucket(stacks->a);
buckets = get_tabs(stacks->a, range);
if (!buckets)
return ;
bucket_algo(stacks, buckets, range);
}
}
void complex(t_stacks *stacks)
{
radix(stacks);
}
void adaptive(t_stacks *stacks, char **tab)
{
int i;
float disorder;
i = 0;
stacks->algo = 4;
while (!ft_isdigit(tab[i][0]) && tab[i])
i++;
disorder = stacks->disorder;
if (disorder < 0.3)
simple(stacks);
else if (disorder < 0.5)
medium(stacks);
else
complex(stacks);
return ;
}