mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 16:51:57 +00:00
fix my medium algo
This commit is contained 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,13 +36,17 @@ 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;
|
||||
}
|
||||
return (min);
|
||||
@@ -59,16 +66,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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user