mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Merge branch 'master' of github.com:DavidGailleton/42-Push_Swap
This commit is contained in:
@@ -16,11 +16,14 @@ int get_first_lower(t_stack *first)
|
||||
{
|
||||
t_stack *tmp;
|
||||
int lower;
|
||||
int pass;
|
||||
|
||||
tmp = first;
|
||||
lower = tmp->value;
|
||||
while (tmp->next != first)
|
||||
pass = 1;
|
||||
while (tmp != first || pass == 1)
|
||||
{
|
||||
pass = 0;
|
||||
if (lower > tmp->value)
|
||||
lower = tmp->value;
|
||||
tmp = tmp->next;
|
||||
@@ -43,6 +46,8 @@ int get_next_lower(t_stack *first, int old_lower)
|
||||
if (old_lower < tmp->value && tmp->value <= next_lower)
|
||||
{
|
||||
next_lower = tmp->value;
|
||||
if (next_lower == -2147483648)
|
||||
return (next_lower);
|
||||
}
|
||||
tmp = tmp->next;
|
||||
}
|
||||
@@ -54,6 +59,8 @@ int calcul_range(int value, int range)
|
||||
int max_range;
|
||||
|
||||
max_range = 0;
|
||||
if (value == 2147483647)
|
||||
return (value);
|
||||
if (value < 0)
|
||||
while (max_range > value)
|
||||
max_range -= range;
|
||||
@@ -80,17 +87,18 @@ int get_number_in_range(int max_range, t_stack *a, int range)
|
||||
int nb_in;
|
||||
t_stack *tmp;
|
||||
t_stack *first;
|
||||
int pass;
|
||||
|
||||
nb_in = 0;
|
||||
tmp = a;
|
||||
pass = 1;
|
||||
first = tmp;
|
||||
while (tmp->next != first)
|
||||
while (tmp != first || pass == 1)
|
||||
{
|
||||
pass = 0;
|
||||
if (in_range(tmp->value, max_range, range))
|
||||
nb_in++;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
if (in_range(tmp->value, max_range, range))
|
||||
nb_in++;
|
||||
return (nb_in);
|
||||
}
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
static int get_max_number(t_stack *first)
|
||||
{
|
||||
int max;
|
||||
int pass;
|
||||
t_stack *a;
|
||||
|
||||
a = first;
|
||||
max = a->value;
|
||||
while (a->next != first)
|
||||
pass = 1;
|
||||
while (a != first || pass == 1)
|
||||
{
|
||||
pass = 0;
|
||||
if (max < a->value)
|
||||
max = a->value;
|
||||
a = a->next;
|
||||
@@ -33,11 +36,14 @@ static int get_min_number(t_stack *first)
|
||||
{
|
||||
int min;
|
||||
t_stack *a;
|
||||
int pass;
|
||||
|
||||
a = first;
|
||||
min = a->value;
|
||||
while (a->next != first)
|
||||
pass = 1;
|
||||
while (a != first || pass == 1)
|
||||
{
|
||||
pass = 0;
|
||||
if (min > a->value)
|
||||
min = a->value;
|
||||
a = a->next;
|
||||
@@ -59,16 +65,16 @@ static int my_sqrt(int nb)
|
||||
|
||||
int range_bucket(t_stack *first)
|
||||
{
|
||||
int len;
|
||||
int diff;
|
||||
int sqrt;
|
||||
int len;
|
||||
long diff;
|
||||
int sqrt;
|
||||
|
||||
len = stack_len(first);
|
||||
diff = get_max_number(first) - get_min_number(first);
|
||||
diff = (long)get_max_number(first) - (long)get_min_number(first);
|
||||
sqrt = my_sqrt(len);
|
||||
if (diff / sqrt < 2)
|
||||
{
|
||||
return (get_max_number(first));
|
||||
}
|
||||
return ((get_max_number(first) - get_min_number(first)) / my_sqrt(len));
|
||||
return (diff / my_sqrt(len));
|
||||
}
|
||||
|
||||
@@ -24,5 +24,3 @@ int check_error(char **tab, int mod)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ static int scan_str_is_digit(char *tab)
|
||||
{
|
||||
if (!ft_isdigit(tab[i]) && (tab[i] == '-' && !ft_isdigit(tab[i + 1])))
|
||||
return (0);
|
||||
if (tab[i] == '+' && !ft_isdigit(tab[i + 1]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
return (1);
|
||||
|
||||
@@ -12,6 +12,13 @@
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
// static int calcul_sign(char c)
|
||||
// {
|
||||
// if (c == '-')
|
||||
// return (-1);
|
||||
// return (1);
|
||||
// }
|
||||
|
||||
static int verif_atoi(const char *nptr)
|
||||
{
|
||||
size_t i;
|
||||
@@ -21,6 +28,8 @@ static int verif_atoi(const char *nptr)
|
||||
i = 0;
|
||||
tmp = 0;
|
||||
before = 0;
|
||||
if (ft_strncmp("-2147483648", nptr, 12))
|
||||
return (1);
|
||||
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == ' ')
|
||||
i++;
|
||||
if (nptr[i] == '-' || nptr[i] == '+')
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "push_swap.h"
|
||||
#include "medium_headers.h"
|
||||
#include "parsing.h"
|
||||
|
||||
void simple(t_stacks *stacks)
|
||||
{
|
||||
@@ -46,8 +47,20 @@ void complex(t_stacks *stacks)
|
||||
radix(stacks);
|
||||
}
|
||||
|
||||
void adaptive(t_stacks *stacks)
|
||||
void adaptive(t_stacks *stacks, char **tab)
|
||||
{
|
||||
(void)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 ;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user