mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
66 lines
1.7 KiB
C
66 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;
|
|
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 ;
|
|
}
|