finish to link all the files

This commit is contained in:
Maoake Teriierooiterai
2026-01-07 10:06:38 +01:00
parent ca732b1b97
commit 95577e5f02
15 changed files with 158 additions and 319 deletions

View File

@@ -11,6 +11,7 @@
/* ************************************************************************** */
#include "push_swap.h"
#include "medium_headers.h"
#include <stdlib.h>
static int path_to_end(t_stacks *piles, int max_range, int range, char c)

View File

@@ -11,43 +11,9 @@
/* ************************************************************************** */
#include "push_swap.h"
#include "medium_headers.h"
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, 'b'))
{
while (!in_range(piles->b->value, one_preset->max_range, range))
rb(piles);
}
else
{
while (!in_range(piles->b->value, one_preset->max_range, range))
{
rrb(piles);
}
}
sort_little_pile(piles);
one_preset->nb_in--;
}
}
int sort_path(t_stacks *piles, int value)
{
int start_path;
int end_path;
start_path = number_move_reverse(piles, value, 's');
if (start_path == 0)
return (1);
end_path = number_move_reverse(piles, value, 'e');
if (start_path < end_path)
return (1);
return (0);
}
int number_move_reverse(t_stacks *piles, int value, char start_end)
static int number_move_reverse(t_stacks *piles, int value, char start_end)
{
int i;
t_stack *tmp;
@@ -74,7 +40,21 @@ int number_move_reverse(t_stacks *piles, int value, char start_end)
return (i);
}
void sort_little_pile(t_stacks *piles)
static int sort_path(t_stacks *piles, int value)
{
int start_path;
int end_path;
start_path = number_move_reverse(piles, value, 's');
if (start_path == 0)
return (1);
end_path = number_move_reverse(piles, value, 'e');
if (start_path < end_path)
return (1);
return (0);
}
static void sort_little_pile(t_stacks *piles)
{
if (!piles->a)
{
@@ -92,3 +72,24 @@ void sort_little_pile(t_stacks *piles)
else
sort_from_right(piles);
}
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, 'b'))
{
while (!in_range(piles->b->value, one_preset->max_range, range))
rb(piles);
}
else
{
while (!in_range(piles->b->value, one_preset->max_range, range))
{
rrb(piles);
}
}
sort_little_pile(piles);
one_preset->nb_in--;
}
}

View File

@@ -11,8 +11,9 @@
/* ************************************************************************** */
#include "push_swap.h"
#include "medium_headers.h"
int get_max_number(t_stack *first)
static int get_max_number(t_stack *first)
{
int max;
t_stack *a;
@@ -28,7 +29,7 @@ int get_max_number(t_stack *first)
return (max);
}
int get_min_number(t_stack *first)
static int get_min_number(t_stack *first)
{
int min;
t_stack *a;
@@ -44,7 +45,7 @@ int get_min_number(t_stack *first)
return (min);
}
int my_sqrt(int nb)
static int my_sqrt(int nb)
{
int i;

View File

@@ -11,9 +11,10 @@
/* ************************************************************************** */
#include "push_swap.h"
#include "medium_headers.h"
#include <stdlib.h>
t_tab *allocate_tab(int range_max, int nb)
static t_tab *allocate_tab(int range_max, int nb)
{
t_tab *tab;
@@ -26,6 +27,45 @@ t_tab *allocate_tab(int range_max, int nb)
return (tab);
}
static t_tab *free_tab(t_tab **first)
{
if (!(*first))
return (NULL);
if ((*first)->next)
free_tab(&(*first)->next);
free(*first);
return (NULL);
}
static t_tab *init_first_tab(t_stack *first, int range)
{
t_tab *tab;
int lower;
int range_max;
lower = get_first_lower(first);
range_max = calcul_range(lower, range);
tab = allocate_tab(range_max, get_number_in_range(range_max, first, range));
if (!tab)
return (NULL);
return (tab);
}
static t_tab *get_next_tab(t_stack *first, t_tab *tab, int range)
{
int lower;
int range_max;
t_tab *next_tab;
lower = get_next_lower(first, tab->max_range);
range_max = calcul_range(lower, range);
next_tab = allocate_tab(range_max,
get_number_in_range(range_max, first, range));
if (!next_tab)
return (NULL);
return (next_tab);
}
t_tab *get_tabs(t_stack *first, int range)
{
t_tab *tmp;
@@ -49,40 +89,3 @@ t_tab *get_tabs(t_stack *first, int range)
}
return (first_tab);
}
t_tab *init_first_tab(t_stack *first, int range)
{
t_tab *tab;
int lower;
int range_max;
lower = get_first_lower(first);
range_max = calcul_range(lower, range);
tab = allocate_tab(range_max, get_number_in_range(range_max, first, range));
if (!tab)
return (NULL);
return (tab);
}
t_tab *get_next_tab(t_stack *first, t_tab *tab, int range)
{
int lower;
int range_max;
t_tab *next_tab;
lower = get_next_lower(first, tab->max_range);
range_max = calcul_range(lower, range);
next_tab = allocate_tab(range_max,
get_number_in_range(range_max, first, range));
return (next_tab);
}
t_tab *free_tab(t_tab **first)
{
if (!(*first))
return (NULL);
if ((*first)->next)
free_tab(&(*first)->next);
free(*first);
return (NULL);
}