mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 00:41:57 +00:00
adding other files cause i put the git on the wrong
This commit is contained in:
42
parsing/ft_atoi.c
Normal file
42
parsing/ft_atoi.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 18:28:17 by mteriier #+# #+# */
|
||||
/* Updated: 2025/12/08 19:30:48 by mteriier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static int calcul_sign(char c)
|
||||
{
|
||||
if (c == '-')
|
||||
return (-1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
size_t i;
|
||||
int sign;
|
||||
int tmp;
|
||||
|
||||
i = 0;
|
||||
sign = 1;
|
||||
tmp = 0;
|
||||
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == ' ')
|
||||
i++;
|
||||
sign = calcul_sign(nptr[i]);
|
||||
if (nptr[i] == '-' || nptr[i] == '+')
|
||||
i++;
|
||||
while (nptr[i] >= '0' && nptr[i] <= '9')
|
||||
{
|
||||
tmp = tmp * 10 + nptr[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return (tmp * sign);
|
||||
}
|
||||
55
parsing/parsing.c
Normal file
55
parsing/parsing.c
Normal file
@@ -0,0 +1,55 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mteriier <mteriier@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/08 16:21:05 by mteriier #+# #+# */
|
||||
/* Updated: 2025/12/09 10:19:17 by mteriier ### ########lyon.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_stack *parsing(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int stock;
|
||||
t_stack *first;
|
||||
t_stack *new;
|
||||
|
||||
i = 1;
|
||||
first = NULL;
|
||||
while (i < argc)
|
||||
{
|
||||
stock = ft_atoi(argv[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_stacks(int argc, char **argv)
|
||||
{
|
||||
t_stacks *stacks;
|
||||
t_stack *a;
|
||||
|
||||
stacks = malloc(sizeof(t_stacks));
|
||||
stacks->a = NULL;
|
||||
stacks->b = NULL;
|
||||
if (!stacks)
|
||||
return (NULL);
|
||||
a = parsing(argc, argv);
|
||||
stacks->a = a;
|
||||
return (stacks);
|
||||
}
|
||||
69
parsing/parsing_2.c
Normal file
69
parsing/parsing_2.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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>
|
||||
#include <stdio.h>
|
||||
|
||||
void print_tabs(t_tab *preset)
|
||||
{
|
||||
t_tab *tab;
|
||||
|
||||
tab = preset;
|
||||
while (tab)
|
||||
{
|
||||
printf("MAX RANGE : [%d]\n", tab->max_range);
|
||||
printf("NUMBER IN : [%d]\n", tab->nb_in);
|
||||
tab = tab->next;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user