finally finish the medium algo

This commit is contained in:
Maoake Teriierooiterai
2026-01-06 13:52:29 +01:00
parent f98dce6f61
commit 80179a5289
5 changed files with 39 additions and 39 deletions

View File

@@ -15,7 +15,7 @@
int path_to_end(t_stacks *piles, int max_range, int range, char c)
{
t_stack *tmp;
t_stack *tmp;
int i;
int first_pass;
@@ -26,11 +26,11 @@ int path_to_end(t_stacks *piles, int max_range, int range, char c)
tmp = tmp->previous;
i = 0;
first_pass = 1;
while (first_pass || tmp != piles->a->previous)
while (first_pass || tmp != piles->b->previous)
{
first_pass = 0;
if (in_range(tmp->value, max_range, range))
tmp = piles->a;
tmp = piles->b;
tmp = tmp->previous;
i++;
}
@@ -39,7 +39,7 @@ int path_to_end(t_stacks *piles, int max_range, int range, char c)
int path_to_start(t_stacks *piles, int max_range, int range, char c)
{
t_stack *tmp;
t_stack *tmp;
int i;
int first_pass;
@@ -49,12 +49,12 @@ int path_to_start(t_stacks *piles, int max_range, int range, char c)
tmp = piles->b;
i = 0;
first_pass = 1;
while (first_pass || tmp != piles->a)
while (first_pass || tmp != piles->b)
{
first_pass = 0;
if (in_range(tmp->value, max_range, range))
{
tmp = piles->a->previous;
tmp = piles->b->previous;
}
tmp = tmp->next;
i++;
@@ -94,6 +94,8 @@ void bucket_algo(t_stacks *piles, t_tab *preset, int range)
t_tab *tmp;
tmp = preset;
while (piles->a)
pb(piles);
while (preset)
{
push_range_to_b(piles, preset, range);

View File

@@ -16,16 +16,16 @@ void push_range_to_b(t_stacks *piles, t_tab *one_preset, int range)
{
while (one_preset->nb_in > 0)
{
if (wich_path(piles, one_preset->max_range, range, 'a'))
if (wich_path(piles, one_preset->max_range, range, 'b'))
{
while (!in_range(piles->a->value, one_preset->max_range, range))
ra(piles);
while (!in_range(piles->b->value, one_preset->max_range, range))
rb(piles);
}
else
{
while (!in_range(piles->a->value, one_preset->max_range, range))
while (!in_range(piles->b->value, one_preset->max_range, range))
{
rra(piles);
rrb(piles);
}
}
sort_little_pile(piles);
@@ -37,7 +37,7 @@ void push_range_to_b(t_stacks *piles, t_tab *one_preset, int range)
int sort_path(t_stacks *piles, int value)
{
int start_path;
int start_path;
int end_path;
start_path = number_move_reverse(piles, value, 's');
@@ -55,10 +55,10 @@ int number_move_reverse(t_stacks *piles, int value, char start_end)
t_stack *tmp;
i = 0;
tmp = piles->b;
if (start_end == 's')
tmp = piles->a;
if (start_end == 's')
{
while(tmp->value < value)
while (tmp->value < value)
{
tmp = tmp->next;
i++;
@@ -67,7 +67,7 @@ int number_move_reverse(t_stacks *piles, int value, char start_end)
else
{
tmp = tmp->previous;
while(tmp->value > value)
while (tmp->value > value)
{
tmp = tmp->previous;
i++;
@@ -78,18 +78,18 @@ int number_move_reverse(t_stacks *piles, int value, char start_end)
void sort_little_pile(t_stacks *piles)
{
if (!piles->b)
if (!piles->a)
{
pb(piles);
pa(piles);
return ;
}
if (piles->b->previous->value < piles->a->value)
if (piles->a->previous->value < piles->b->value)
{
pb(piles);
rb(piles);
pa(piles);
ra(piles);
return ;
}
if (sort_path(piles, piles->a->value))
if (sort_path(piles, piles->b->value))
sort_from_left(piles);
else
sort_from_right(piles);

View File

@@ -16,18 +16,18 @@ void sort_from_left(t_stacks *piles)
{
int i;
i = 0;
while (piles->a->value > piles->b->value)
i = 0;
while (piles->b->value > piles->a->value)
{
rb(piles);
ra(piles);
i++;
}
pb(piles);
pa(piles);
while (i > 0)
{
rrb(piles);
i--;
}
{
rra(piles);
i--;
}
}
void sort_from_right(t_stacks *piles)
@@ -35,15 +35,15 @@ void sort_from_right(t_stacks *piles)
int i;
i = 0;
while (piles->a->value < piles->b->previous->value)
while (piles->b->value < piles->a->previous->value)
{
rrb(piles);
rra(piles);
i++;
}
pb(piles);
pa(piles);
while (i >= 0)
{
rb(piles);
i--;
}
{
ra(piles);
i--;
}
}

View File

@@ -41,5 +41,3 @@ int is_highest(t_stack *stack, t_stack *node, int len)
}
return (1);
}