replacing piles by stacks

This commit is contained in:
Maoake Teriierooiterai
2026-01-09 07:24:32 +01:00
parent 32a0668b62
commit c131843bc0
12 changed files with 101 additions and 101 deletions

View File

@@ -14,48 +14,48 @@
#include "medium_headers.h"
#include <stdlib.h>
static int path_to_end(t_stacks *piles, int max_range, int range, char c)
static int path_to_end(t_stacks *stacks, int max_range, int range, char c)
{
t_stack *tmp;
int i;
int first_pass;
if (c == 'a')
tmp = piles->a;
tmp = stacks->a;
else
tmp = piles->b;
tmp = stacks->b;
tmp = tmp->previous;
i = 0;
first_pass = 1;
while (first_pass || tmp != piles->b->previous)
while (first_pass || tmp != stacks->b->previous)
{
first_pass = 0;
if (in_range(tmp->value, max_range, range))
tmp = piles->b;
tmp = stacks->b;
tmp = tmp->previous;
i++;
}
return (i);
}
static int path_to_start(t_stacks *piles, int max_range, int range, char c)
static int path_to_start(t_stacks *stacks, int max_range, int range, char c)
{
t_stack *tmp;
int i;
int first_pass;
if (c == 'a')
tmp = piles->a;
tmp = stacks->a;
else
tmp = piles->b;
tmp = stacks->b;
i = 0;
first_pass = 1;
while (first_pass || tmp != piles->b)
while (first_pass || tmp != stacks->b)
{
first_pass = 0;
if (in_range(tmp->value, max_range, range))
{
tmp = piles->b->previous;
tmp = stacks->b->previous;
}
tmp = tmp->next;
i++;
@@ -63,13 +63,13 @@ static int path_to_start(t_stacks *piles, int max_range, int range, char c)
return (i);
}
int wich_path(t_stacks *piles, int max_range, int range, char c)
int wich_path(t_stacks *stacks, int max_range, int range, char c)
{
int path_start;
int path_end;
path_start = path_to_start(piles, max_range, range, c);
path_end = path_to_end(piles, max_range, range, c);
path_start = path_to_start(stacks, max_range, range, c);
path_end = path_to_end(stacks, max_range, range, c);
if (path_start < path_end)
return (1);
return (0);
@@ -90,16 +90,16 @@ int stack_len(t_stack *stack)
return (i);
}
void bucket_algo(t_stacks *piles, t_tab *preset, int range)
void bucket_algo(t_stacks *stacks, t_tab *preset, int range)
{
t_tab *tmp;
tmp = preset;
while (piles->a)
pb(piles);
while (stacks->a)
pb(stacks);
while (preset)
{
push_range_to_b(piles, preset, range);
push_range_to_b(stacks, preset, range);
if (preset->next)
tmp = preset->next;
else
@@ -108,7 +108,7 @@ void bucket_algo(t_stacks *piles, t_tab *preset, int range)
free(preset);
preset = tmp;
}
while (piles->b)
pa(piles);
while (stacks->b)
pa(stacks);
return ;
}

View File

@@ -13,13 +13,13 @@
#include "push_swap.h"
#include "medium_headers.h"
static int number_move_reverse(t_stacks *piles, int value, char start_end)
static int number_move_reverse(t_stacks *stacks, int value, char start_end)
{
int i;
t_stack *tmp;
i = 0;
tmp = piles->a;
tmp = stacks->a;
if (start_end == 's')
{
while (tmp->value < value)
@@ -40,56 +40,56 @@ static int number_move_reverse(t_stacks *piles, int value, char start_end)
return (i);
}
static int sort_path(t_stacks *piles, int value)
static int sort_path(t_stacks *stacks, int value)
{
int start_path;
int end_path;
start_path = number_move_reverse(piles, value, 's');
start_path = number_move_reverse(stacks, value, 's');
if (start_path == 0)
return (1);
end_path = number_move_reverse(piles, value, 'e');
end_path = number_move_reverse(stacks, value, 'e');
if (start_path < end_path)
return (1);
return (0);
}
static void sort_little_pile(t_stacks *piles)
static void sort_little_pile(t_stacks *stacks)
{
if (!piles->a)
if (!stacks->a)
{
pa(piles);
pa(stacks);
return ;
}
if (piles->a->previous->value < piles->b->value)
if (stacks->a->previous->value < stacks->b->value)
{
pa(piles);
ra(piles);
pa(stacks);
ra(stacks);
return ;
}
if (sort_path(piles, piles->b->value))
sort_from_left(piles);
if (sort_path(stacks, stacks->b->value))
sort_from_left(stacks);
else
sort_from_right(piles);
sort_from_right(stacks);
}
void push_range_to_b(t_stacks *piles, t_tab *one_preset, int range)
void push_range_to_b(t_stacks *stacks, t_tab *one_preset, int range)
{
while (one_preset->nb_in > 0)
{
if (wich_path(piles, one_preset->max_range, range, 'b'))
if (wich_path(stacks, one_preset->max_range, range, 'b'))
{
while (!in_range(piles->b->value, one_preset->max_range, range))
rb(piles);
while (!in_range(stacks->b->value, one_preset->max_range, range))
rb(stacks);
}
else
{
while (!in_range(piles->b->value, one_preset->max_range, range))
while (!in_range(stacks->b->value, one_preset->max_range, range))
{
rrb(piles);
rrb(stacks);
}
}
sort_little_pile(piles);
sort_little_pile(stacks);
one_preset->nb_in--;
}
}

View File

@@ -12,38 +12,38 @@
#include "push_swap.h"
void sort_from_left(t_stacks *piles)
void sort_from_left(t_stacks *stacks)
{
int i;
i = 0;
while (piles->b->value > piles->a->value)
while (stacks->b->value > stacks->a->value)
{
ra(piles);
ra(stacks);
i++;
}
pa(piles);
pa(stacks);
while (i > 0)
{
rra(piles);
rra(stacks);
i--;
}
}
void sort_from_right(t_stacks *piles)
void sort_from_right(t_stacks *stacks)
{
int i;
i = 0;
while (piles->b->value < piles->a->previous->value)
while (stacks->b->value < stacks->a->previous->value)
{
rra(piles);
rra(stacks);
i++;
}
pa(piles);
pa(stacks);
while (i >= 0)
{
ra(piles);
ra(stacks);
i--;
}
}