finish the disorder

This commit is contained in:
Maoake Teriierooiterai
2026-01-12 12:37:56 +01:00
parent 69dc80e498
commit ccccc3b640
10 changed files with 28 additions and 19 deletions

View File

@@ -58,7 +58,6 @@ int calcul_range(int value, int range)
{
int max_range;
max_range = 0;
if (value == 2147483647)
return (value);

View File

@@ -22,7 +22,7 @@ static int get_max_number(t_stack *first)
a = first;
max = a->value;
pass = 1;
while (a!= first || pass == 1)
while (a != first || pass == 1)
{
pass = 0;
if (max < a->value)
@@ -46,7 +46,6 @@ static int get_min_number(t_stack *first)
pass = 0;
if (min > a->value)
min = a->value;
a = a->next;
}
return (min);

View File

@@ -24,5 +24,3 @@ int check_error(char **tab, int mod)
return (0);
return (1);
}

View File

@@ -20,6 +20,7 @@ static int is_exist_flag(char **tab, int pos)
if (ft_strncmp(tab[pos], "--bench", 7)
|| ft_strncmp(tab[pos], "--simple", 8)
|| ft_strncmp(tab[pos], "--medium", 8)
|| ft_strncmp(tab[pos], "--adaptive", 10)
|| ft_strncmp(tab[pos], "--complex", 9))
verif = 1;
return (verif);
@@ -40,7 +41,7 @@ static int verif_exist_flag(char **tab, int mod)
return (verif);
}
static int verif_double_flag(char **tab, int mod)
static int verif_double_flag(char **tab, int mod)
{
int verif;
@@ -57,4 +58,4 @@ int verif_flag(char **tab, int mod)
if (verif_double_flag(tab, mod) && verif_exist_flag(tab, mod))
return (1);
return (0);
}
}

View File

@@ -12,6 +12,7 @@
#include "push_swap.h"
#include "medium_headers.h"
#include "parsing.h"
void simple(t_stacks *stacks)
{
@@ -46,10 +47,20 @@ void complex(t_stacks *stacks)
radix(stacks);
}
void adaptive(t_stacks *stacks)
void adaptive(t_stacks *stacks, char **tab)
{
//simple(stacks);
medium(stacks);
//complex(stacks);
int i;
float disorder;
i = 0;
while (!ft_isdigit(tab[i][0]) && tab[i])
i++;
disorder = compute_disorder(tab, i - 1);
if (disorder < 0.3)
simple(stacks);
else if (disorder < 0.46)
medium(stacks);
else
complex(stacks);
return ;
}

View File

@@ -102,9 +102,9 @@ void flags(int pos, int pos_b, char **argv, t_stacks *stacks)
else if (ft_strncmp(argv[pos], "--complex", 30) && pos > 0)
complex(stacks);
else if (ft_strncmp(argv[pos], "--adaptive", 30) && pos > 0)
adaptive(stacks);
adaptive(stacks, argv);
else
adaptive(stacks);
adaptive(stacks, argv);
if (pos_b > 0)
stacks->bench = 1;
}

View File

@@ -16,7 +16,7 @@
void simple(t_stacks *stacks);
void medium(t_stacks *stacks);
void complex(t_stacks *stacks);
void adaptive(t_stacks *stacks);
void adaptive(t_stacks *stacks, char **tab);
void flags(int pos, int pos_b, char **argv, t_stacks *stacks);
int pos_bench(char **argv, int mod);
int pos_flag(char **argv, int mod);

View File

@@ -33,6 +33,6 @@ int ft_strlcpy(char *dst, const char *src, int size);
int ft_strlcat(char *dst, const char *src, int size);
char *join_all(int argc, char **argv);
char **split_all(char *tab);
float compute_disorder(char **strs);
float compute_disorder(char **strs, int pos);
#endif

View File

@@ -11,6 +11,7 @@
/* ************************************************************************** */
#include "push_swap.h"
#include "parsing.h"
static int strs_len(char **strs)
{
@@ -22,7 +23,7 @@ static int strs_len(char **strs)
return (i);
}
float compute_disorder(char **strs)
float compute_disorder(char **strs, int pos)
{
float mistakes;
float total_pairs;
@@ -31,14 +32,14 @@ float compute_disorder(char **strs)
mistakes = 0;
total_pairs = 0;
i = 0;
i = pos;
while (i < strs_len(strs))
{
j = i + 1;
while (j < strs_len(strs))
{
total_pairs += 1;
if (strs[i] > strs[j])
if (ft_atoi(strs[i]) > ft_atoi(strs[j]))
mistakes += 1;
j++;
}

View File

@@ -14,7 +14,7 @@
char *ft_strjoin(char const *s1, char const *s2)
{
int total_len;
int total_len;
char *tmp;
total_len = ft_strlen(s1) + ft_strlen(s2);