mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
adding the flags
This commit is contained in:
6
Makefile
6
Makefile
@@ -14,6 +14,8 @@ PARS_DIR = parsing
|
||||
|
||||
MEDIUM_DIR = medium
|
||||
|
||||
FLAGS_DIR = flags
|
||||
|
||||
INCLUDES = headers
|
||||
|
||||
#============================
|
||||
@@ -24,7 +26,9 @@ SRC = main.c test_one.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
|
||||
|
||||
|
||||
42
flags/algorithms_sort.c
Normal file
42
flags/algorithms_sort.c
Normal 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
29
flags/flag.c
Normal 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
22
headers/flags.h
Normal 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
|
||||
@@ -16,5 +16,6 @@
|
||||
int ft_atoi(const char *nptr);
|
||||
t_stacks *init_big_stacks2(int *tab, int len);
|
||||
t_stacks *init_big_stacks(int argc, char **argv);
|
||||
int ft_strncmp(const char *s1, const char *s2, int n);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -45,6 +45,7 @@ t_stack *new_stack(int value);
|
||||
void stack_add_back(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 free_all(t_stacks *piles);
|
||||
/* STACKS LEN FILES */
|
||||
int stack_a_len(t_stacks *stacks);
|
||||
int stack_b_len(t_stacks *stacks);
|
||||
|
||||
25
parsing/ft_strncmp.c
Normal file
25
parsing/ft_strncmp.c
Normal 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]);
|
||||
}
|
||||
@@ -21,3 +21,12 @@ void stack_clear_all(t_stack *stack, t_stack *first)
|
||||
stack_clear_all(stack->next, first);
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user