Merge branch 'master' into radix

This commit is contained in:
2026-01-07 14:53:07 +00:00
15 changed files with 144 additions and 67 deletions

2
.gitignore vendored
View File

@@ -58,7 +58,7 @@ dkms.conf
*.swp *.swp
# Executable # Executable
pushswap push_swap
# File obj # File obj
obj/ obj/

View File

@@ -16,6 +16,8 @@ MEDIUM_DIR = medium
COMPLEX_DIR = radix COMPLEX_DIR = radix
FLAGS_DIR = flags
INCLUDES = headers INCLUDES = headers
#============================ #============================
@@ -26,7 +28,9 @@ SRC = main.c test_one.c
INSERTION = insertion.c INSERTION = insertion.c
PARSING = ft_atoi.c parsing.c parsing_2.c FLAGS_FILES = algorithms_sort.c flag.c
PARSING = ft_atoi.c parsing.c ft_strncmp.c
STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c stacks_len.c swap.c print_stacks.c STACK_UTILS = push.c rev_rotate.c rotate.c stack_add.c stack_remove.c stacks_len.c swap.c print_stacks.c

View File

@@ -24,7 +24,8 @@ static int to_insert(t_stacks *stacks, int sorted)
a = stacks->a; a = stacks->a;
while (i < sorted) while (i < sorted)
{ {
if (stacks->b->value > a->previous->value && stacks->b->value <= a->value) if (stacks->b->value > a->previous->value
&& stacks->b->value <= a->value)
return (i); return (i);
a = a->previous; a = a->previous;
i++; i++;

View File

@@ -32,11 +32,14 @@ int get_next_lower(t_stack *first, int old_lower)
{ {
t_stack *tmp; t_stack *tmp;
int next_lower; int next_lower;
int skip_first;
tmp = first; tmp = first;
skip_first = 1;
next_lower = 2147483647; next_lower = 2147483647;
while (tmp->next != first) while (tmp != first || skip_first)
{ {
skip_first = 0;
if (old_lower < tmp->value && tmp->value <= next_lower) if (old_lower < tmp->value && tmp->value <= next_lower)
{ {
next_lower = tmp->value; next_lower = tmp->value;

View File

@@ -64,7 +64,7 @@ int range_bucket(t_stack *first)
int sqrt; int sqrt;
len = stack_len(first); len = stack_len(first);
diff = (get_max_number(first) - get_min_number(first)) ; diff = get_max_number(first) - get_min_number(first);
sqrt = my_sqrt(len); sqrt = my_sqrt(len);
if (diff / sqrt < 2) if (diff / sqrt < 2)
{ {

42
flags/algorithms_sort.c Normal file
View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algorithms_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 12:15:02 by mteriier #+# #+# */
/* Updated: 2026/01/07 12:15:05 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "medium_algo.h"
void simple(t_stacks *piles)
{
int len;
len = stack_a_len(piles);
insertion(piles, len);
}
void medium(t_stacks *piles)
{
t_tab *buckets;
int range;
range = range_bucket(piles->a);
buckets = get_tabs(piles->a, range);
bucket_algo(piles, buckets, range);
}
void complex(t_stacks *piles)
{
return ;
}
void adaptive(t_stacks *piles)
{
return ;
}

28
flags/flag.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flag.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 12:39:29 by mteriier #+# #+# */
/* Updated: 2026/01/07 12:39:31 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include "parsing.h"
void flags(int pos, char **argv, t_stacks *piles)
{
if (ft_strncmp(argv[pos], "--simple", 30) && pos > 0)
simple(piles);
else if (ft_strncmp(argv[pos], "--medium", 30) && pos > 0)
medium(piles);
else if (ft_strncmp(argv[pos], "--complex", 30) && pos > 0)
complex(piles);
else if (ft_strncmp(argv[pos], "--adaptive", 30) && pos > 0)
adaptive(piles);
else
adaptive(piles);
}

22
headers/flags.h Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* flags.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 13:05:52 by mteriier #+# #+# */
/* Updated: 2026/01/07 13:05:53 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef FLAGS_H
# define FLAGS_H
void simple(t_stacks *piles);
void medium(t_stacks *piles);
void complex(t_stacks *piles);
void adaptive(t_stacks *piles);
void flags(int pos, char **argv, t_stacks *piles);
#endif

View File

@@ -14,7 +14,7 @@
# define PARSING_H # define PARSING_H
int ft_atoi(const char *nptr); int ft_atoi(const char *nptr);
t_stacks *init_big_stacks2(int *tab, int len);
t_stacks *init_big_stacks(int argc, char **argv); t_stacks *init_big_stacks(int argc, char **argv);
int ft_strncmp(const char *s1, const char *s2, int n);
#endif #endif

View File

@@ -45,6 +45,7 @@ t_stack *new_stack(int value);
void stack_add_back(t_stack **stack, t_stack *new); void stack_add_back(t_stack **stack, t_stack *new);
void stack_add_front(t_stack **stack, t_stack *new); void stack_add_front(t_stack **stack, t_stack *new);
void stack_clear_all(t_stack *stack, t_stack *first); void stack_clear_all(t_stack *stack, t_stack *first);
void free_all(t_stacks *piles);
/* STACKS LEN FILES */ /* STACKS LEN FILES */
int stack_a_len(t_stacks *stacks); int stack_a_len(t_stacks *stacks);
int stack_b_len(t_stacks *stacks); int stack_b_len(t_stacks *stacks);

25
parsing/ft_strncmp.c Normal file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/07 12:36:38 by mteriier #+# #+# */
/* Updated: 2026/01/07 12:36:40 by mteriier ### ########lyon.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(const char *s1, const char *s2, int n)
{
int i;
i = 0;
if (n == 0)
return (0);
while (i < n - 1 && s1[i] && s1[i] == s2[i])
{
i++;
}
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}

View File

@@ -1,55 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mteriier <mteriier@student.lyon42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/22 13:10:58 by mteriier #+# #+# */
/* Updated: 2025/12/22 13:11:21 by mteriier ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <stdlib.h>
static t_stack *parsing2(int *tab, int len)
{
int i;
int stock;
t_stack *first;
t_stack *new;
i = 0;
first = NULL;
while (i < len)
{
stock = tab[i];
new = new_stack(stock);
if (!new && !first)
return (NULL);
else if (!new)
{
stack_clear_all(first, first);
return (NULL);
}
stack_add_back(&first, new);
i++;
}
return (first);
}
t_stacks *init_big_stacks2(int *tab, int len)
{
t_stacks *stacks;
t_stack *a;
stacks = malloc(sizeof(t_stacks));
stacks->a = NULL;
stacks->b = NULL;
if (!stacks)
return (NULL);
a = parsing2(tab, len);
stacks->a = a;
return (stacks);
}

View File

@@ -21,3 +21,12 @@ void stack_clear_all(t_stack *stack, t_stack *first)
stack_clear_all(stack->next, first); stack_clear_all(stack->next, first);
free(stack); free(stack);
} }
void free_all(t_stacks *piles)
{
if (piles->a)
stack_clear_all(piles->a, piles->a);
if (piles->b)
stack_clear_all(piles->b, piles->b);
free(piles);
}

View File

@@ -29,10 +29,7 @@ int test1(int argc, char **argv)
//bucket_algo(piles, preset, range_bucket(piles->a)); //bucket_algo(piles, preset, range_bucket(piles->a));
radix(piles); radix(piles);
} }
if (piles->a) free_all(piles);
stack_clear_all(piles->a, piles->a);
if (piles->b)
stack_clear_all(piles->b, piles->b);
free(piles); free(piles);
return (0); return (0);
} }