adding the flags

This commit is contained in:
Maoake Teriierooiterai
2026-01-07 13:13:30 +01:00
parent 0d9b46c748
commit 93e8c10b27
8 changed files with 134 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ PARS_DIR = parsing
MEDIUM_DIR = medium MEDIUM_DIR = medium
FLAGS_DIR = flags
INCLUDES = headers INCLUDES = headers
#============================ #============================
@@ -24,7 +26,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 parsing_2.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

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 ;
}

29
flags/flag.c Normal file
View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

@@ -16,5 +16,6 @@
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_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

@@ -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);
}