mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
Merge branch 'master' of github.com:DavidGailleton/42-Push_Swap
This commit is contained in:
4
Makefile
4
Makefile
@@ -20,7 +20,7 @@ FLAGS_DIR = flags
|
||||
|
||||
CHECKER_DIR = checker
|
||||
|
||||
INCLUDES = headers
|
||||
INCLUDES = includes
|
||||
|
||||
#============================
|
||||
# ALL FILES WITHOUT PATH
|
||||
@@ -37,7 +37,7 @@ PARSING = ft_atoi.c parsing.c ft_strncmp.c ft_split.c ft_strlen.c ft_substr.c ch
|
||||
|
||||
CHECKER_FILES = check_error.c verif_flag.c verif_is_digit.c verif_overflow.c verif_double.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
|
||||
|
||||
MEDIUM_ALGO = utils_medium.c utils_struct_tab.c utils_medium_two.c sort_utils.c sort_utils_two.c medium_algo.c
|
||||
|
||||
|
||||
@@ -11,6 +11,17 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "check_error.h"
|
||||
#include "parsing.h"
|
||||
|
||||
int verif_is_number(char **tab)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = len_split(tab);
|
||||
if (tab[len - 1][0] == '-' && !ft_isdigit(tab[len - 1][1]))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int check_error(char **tab, int mod)
|
||||
{
|
||||
@@ -22,5 +33,7 @@ int check_error(char **tab, int mod)
|
||||
return (0);
|
||||
if (!verif_double(tab, mod))
|
||||
return (0);
|
||||
if (!verif_is_number(tab))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ static int is_exist_flag(char **tab, int pos)
|
||||
int verif;
|
||||
|
||||
verif = 0;
|
||||
if (ft_strncmp(tab[pos], "--bench", 7)
|
||||
|| ft_strncmp(tab[pos], "--simple", 8)
|
||||
|| ft_strncmp(tab[pos], "--medium", 8)
|
||||
|| ft_strncmp(tab[pos], "--adaptive", 10)
|
||||
|| ft_strncmp(tab[pos], "--complex", 9))
|
||||
if (ft_strncmp(tab[pos], "--bench", 30)
|
||||
|| ft_strncmp(tab[pos], "--simple", 30)
|
||||
|| ft_strncmp(tab[pos], "--medium", 30)
|
||||
|| ft_strncmp(tab[pos], "--adaptive", 30)
|
||||
|| ft_strncmp(tab[pos], "--complex", 30))
|
||||
verif = 1;
|
||||
return (verif);
|
||||
}
|
||||
|
||||
@@ -12,16 +12,17 @@
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
static int scan_str_is_digit(char *tab)
|
||||
int scan_str_is_digit(char *tab)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i])
|
||||
{
|
||||
if (!ft_isdigit(tab[i]) && (tab[i] == '-' && !ft_isdigit(tab[i + 1])))
|
||||
return (0);
|
||||
if (tab[i] == '+' && !ft_isdigit(tab[i + 1]))
|
||||
if ((tab[i] == '+' || tab[i] == '-') && ft_isdigit(tab[i + 1])
|
||||
&& tab[i + 1])
|
||||
i++;
|
||||
if (!ft_isdigit(tab[i]))
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ static int verif_atoi(const char *nptr)
|
||||
i = 0;
|
||||
tmp = 0;
|
||||
before = 0;
|
||||
if (ft_strncmp("-2147483648", nptr, 12))
|
||||
if (ft_strncmp(nptr, "-2147483648", 15))
|
||||
return (1);
|
||||
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == ' ')
|
||||
i++;
|
||||
|
||||
@@ -37,6 +37,8 @@ void medium(t_stacks *stacks)
|
||||
{
|
||||
range = range_bucket(stacks->a);
|
||||
buckets = get_tabs(stacks->a, range);
|
||||
if (!buckets)
|
||||
return ;
|
||||
bucket_algo(stacks, buckets, range);
|
||||
}
|
||||
}
|
||||
@@ -58,7 +60,7 @@ void adaptive(t_stacks *stacks, char **tab)
|
||||
disorder = compute_disorder(tab, i - 1);
|
||||
if (disorder < 0.3)
|
||||
simple(stacks);
|
||||
else if (disorder < 0.46)
|
||||
else if (disorder < 0.5)
|
||||
medium(stacks);
|
||||
else
|
||||
complex(stacks);
|
||||
|
||||
40
flags/flag.c
40
flags/flag.c
@@ -14,48 +14,14 @@
|
||||
#include "parsing.h"
|
||||
#include "flags.h"
|
||||
|
||||
static int verif_arg(char *argv)
|
||||
{
|
||||
int len;
|
||||
int verif;
|
||||
char **split;
|
||||
|
||||
split = ft_split(argv, ' ');
|
||||
if (!split)
|
||||
return (-1);
|
||||
len = len_split(split);
|
||||
if (len > 1)
|
||||
verif = 1;
|
||||
else
|
||||
verif = 0;
|
||||
free_tab(split);
|
||||
return (verif);
|
||||
}
|
||||
|
||||
int calcul_mod(int argc, char **argv)
|
||||
{
|
||||
int mod;
|
||||
|
||||
if (verif_arg(argv[argc -1]) == 0)
|
||||
{
|
||||
if (ft_strncmp("--", argv[1], 2) && ft_strncmp("--", argv[2], 2))
|
||||
mod = 2;
|
||||
else if (ft_strncmp("--", argv[1], 2) && !ft_strncmp("--", argv[2], 2))
|
||||
mod = 1;
|
||||
else
|
||||
mod = 0;
|
||||
}
|
||||
else if (verif_arg(argv[argc -1]) == 1)
|
||||
{
|
||||
if (ft_strncmp("--", argv[1], 2) && ft_strncmp("--", argv[2], 2))
|
||||
mod = 5;
|
||||
else if (ft_strncmp("--", argv[1], 2) && !ft_strncmp("--", argv[2], 2))
|
||||
mod = 4;
|
||||
else
|
||||
mod = 3;
|
||||
}
|
||||
else
|
||||
mod = -1;
|
||||
while (argv[mod] && !ft_isdigit(argv[mod][0]) && mod < argc)
|
||||
mod++;
|
||||
mod--;
|
||||
return (mod);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,5 +18,6 @@ int check_error(char **tab, int mod);
|
||||
int verif_is_digit(char **tab, int mod);
|
||||
int verif_overflow(char **tab, int mod);
|
||||
int verif_double(char **tab, int mod);
|
||||
int scan_str_is_digit(char *tab);
|
||||
|
||||
#endif
|
||||
@@ -40,8 +40,6 @@ typedef struct s_stacks
|
||||
unsigned int ss;
|
||||
} t_stacks;
|
||||
|
||||
/* PRINT STACK FUNCTION*/
|
||||
void print_stacks(t_stacks *stacks, int len, t_stack *a, t_stack *b);
|
||||
/*STACK_FUNCTIONS*/
|
||||
void pa(t_stacks *stacks);
|
||||
void pb(t_stacks *stacks);
|
||||
2
main.c
2
main.c
@@ -22,6 +22,8 @@ int main(int argc, char **argv)
|
||||
int mod;
|
||||
int len;
|
||||
|
||||
if (argc < 2)
|
||||
return (0);
|
||||
tab = split_all(join_all(argc, argv));
|
||||
if (!tab)
|
||||
return (0);
|
||||
|
||||
@@ -16,13 +16,7 @@
|
||||
|
||||
int wich_mod(int mod)
|
||||
{
|
||||
if (mod == 0)
|
||||
return (1);
|
||||
else if (mod == 1)
|
||||
return (2);
|
||||
else if (mod == 2)
|
||||
return (3);
|
||||
return (0);
|
||||
return (mod % 3 + 1);
|
||||
}
|
||||
|
||||
static t_stack *parsing(int argc, char **argv, int mod)
|
||||
@@ -51,28 +45,6 @@ static t_stack *parsing(int argc, char **argv, int mod)
|
||||
return (first);
|
||||
}
|
||||
|
||||
static t_stack *special_parsing(char **argv, int mod)
|
||||
{
|
||||
t_stack *a;
|
||||
char **split_tab;
|
||||
int len;
|
||||
int i;
|
||||
|
||||
i = mod % 3 + 1;
|
||||
split_tab = ft_split(argv[i], ' ');
|
||||
if (!split_tab)
|
||||
return (NULL);
|
||||
len = len_split(split_tab);
|
||||
a = parsing(len, split_tab, mod);
|
||||
if (!a)
|
||||
{
|
||||
free_tab(split_tab);
|
||||
return (NULL);
|
||||
}
|
||||
free_tab(split_tab);
|
||||
return (a);
|
||||
}
|
||||
|
||||
static void set_t_stacks(t_stacks *stacks)
|
||||
{
|
||||
stacks->a = NULL;
|
||||
@@ -102,10 +74,7 @@ t_stacks *init_stacks(int argc, char **argv, int mod)
|
||||
if (!stacks)
|
||||
return (NULL);
|
||||
set_t_stacks(stacks);
|
||||
if (mod == 0 || mod == 1 || mod == 2)
|
||||
a = parsing(argc, argv, mod);
|
||||
else
|
||||
a = special_parsing(argv, mod);
|
||||
if (!a)
|
||||
{
|
||||
free(stacks);
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* print_stacks.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/09 13:10:00 by dgaillet #+# #+# */
|
||||
/* Updated: 2025/12/09 13:36:03 by dgaillet ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void print_stacks(t_stacks *stacks, int len, t_stack *a, t_stack *b)
|
||||
{
|
||||
int a_len;
|
||||
int b_len;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
a_len = stack_a_len(stacks);
|
||||
b_len = stack_b_len(stacks);
|
||||
while (i < len)
|
||||
{
|
||||
if (a_len >= len - i)
|
||||
{
|
||||
printf("%d", a->value);
|
||||
a = a->next;
|
||||
}
|
||||
printf("\t");
|
||||
if (b_len >= len - i)
|
||||
{
|
||||
printf("%d", b->value);
|
||||
b = b->next;
|
||||
}
|
||||
printf("\n");
|
||||
i++;
|
||||
}
|
||||
printf("_\t_\nA\tB\n\n");
|
||||
}
|
||||
@@ -27,7 +27,10 @@ int test1(char **tab, int len, int mod)
|
||||
if (!stacks)
|
||||
return (0);
|
||||
if (check_order(stacks->a))
|
||||
{
|
||||
free_all(stacks);
|
||||
return (0);
|
||||
}
|
||||
flags(pos_flag(tab, mod), pos_bench(tab, mod), tab, stacks);
|
||||
if (stacks->bench == 1)
|
||||
print_bench(stacks);
|
||||
|
||||
Reference in New Issue
Block a user