mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
setting up the searching path if i start from the top or from the bot need to be testing out
This commit is contained in:
@@ -12,6 +12,59 @@
|
|||||||
|
|
||||||
#include "push_swap.h"
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
int path_to_end(t_stacks *piles, int max_range, int range)
|
||||||
|
{
|
||||||
|
t_stack *tmp;
|
||||||
|
int i;
|
||||||
|
int first_pass;
|
||||||
|
|
||||||
|
tmp = piles->a;
|
||||||
|
tmp = tmp->previous;
|
||||||
|
i = 0;
|
||||||
|
first_pass = 1
|
||||||
|
while (first_pass || tmp != piles->a->previous)
|
||||||
|
{
|
||||||
|
first_pass = 0;
|
||||||
|
if (in_range(tmp->value, max_range, range))
|
||||||
|
tmp = piles->a->previous;
|
||||||
|
tmp = tmp->previous;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int path_to_start(t_stacks *piles, int max_range, int range)
|
||||||
|
{
|
||||||
|
t_stack *tmp;
|
||||||
|
int i;
|
||||||
|
int first_pass;
|
||||||
|
|
||||||
|
tmp = piles ->a;
|
||||||
|
i = 0;
|
||||||
|
first_pass = 1;
|
||||||
|
while (first_pass || tmp != piles->a)
|
||||||
|
{
|
||||||
|
first_pass = 0;
|
||||||
|
if (in_range(tmp->value, max_range, range))
|
||||||
|
tmp = piles->a;
|
||||||
|
tmp = tmp->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int wich_path(t_stacks *piles, int max_range, int range)
|
||||||
|
{
|
||||||
|
int path_start;
|
||||||
|
int path_end;
|
||||||
|
|
||||||
|
path_start = path_to_start(piles, max_range, range);
|
||||||
|
path_end = path_to_end(piles, max_range, range);
|
||||||
|
if (path_start < path_end)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
void bucket_algo(void)
|
void bucket_algo(void)
|
||||||
{
|
{
|
||||||
return ;
|
return ;
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ t_tab *free_tab(t_tab **first);
|
|||||||
t_tab *get_next_tab(t_stack *first, t_tab *tab, int range);
|
t_tab *get_next_tab(t_stack *first, t_tab *tab, int range);
|
||||||
t_tab *init_first_tab(t_stack *first, int range);
|
t_tab *init_first_tab(t_stack *first, int range);
|
||||||
t_tab *allocate_tab(int range_max, int nb);
|
t_tab *allocate_tab(int range_max, int nb);
|
||||||
|
int wich_path(t_stacks *piles, int max_range, int range);
|
||||||
|
int path_to_start(t_stacks *piles, int max_range, int range);
|
||||||
|
int path_to_end(t_stacks *piles, int max_range, int range);
|
||||||
/*FUNCTION IN MAIN*/
|
/*FUNCTION IN MAIN*/
|
||||||
void print_all_stack(t_stack *stack, t_stack *first, char pile);
|
void print_all_stack(t_stack *stack, t_stack *first, char pile);
|
||||||
int verif_no_double(int *tab, int len, int value);
|
int verif_no_double(int *tab, int len, int value);
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ int test2(char **argv)
|
|||||||
tab = auto_shuffle(len);
|
tab = auto_shuffle(len);
|
||||||
piles = init_big_stacks2(tab, len);
|
piles = init_big_stacks2(tab, len);
|
||||||
preset = get_tabs(piles->a, range_bucket(piles->a));
|
preset = get_tabs(piles->a, range_bucket(piles->a));
|
||||||
print_tabs(preset);
|
|
||||||
free(tab);
|
free(tab);
|
||||||
free_tab(&preset);
|
free_tab(&preset);
|
||||||
if (piles->a)
|
if (piles->a)
|
||||||
|
|||||||
Reference in New Issue
Block a user