starting the bonus and modify the name folder headers -> includes

This commit is contained in:
Maoake Teriierooiterai
2026-01-13 09:40:15 +01:00
parent 696f1ca2d5
commit 7d2fed6e76
18 changed files with 333 additions and 1 deletions

54
bonus/utils/stack_add.c Normal file
View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack_add.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/08 15:52:40 by dgaillet #+# #+# */
/* Updated: 2025/12/12 11:39:09 by dgaillet ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
#include <stdlib.h>
t_stack *new_stack(int value)
{
t_stack *new;
new = malloc(sizeof(t_stack));
if (!new)
return (NULL);
new->value = value;
new->next = NULL;
new->previous = NULL;
return (new);
}
void stack_add_back(t_stack **stack, t_stack *new)
{
if (!stack || !new)
return ;
if (*stack == NULL)
{
(*stack) = new;
new->next = new;
new->previous = new;
}
else
{
(*stack)->previous->next = new;
new->previous = (*stack)->previous;
(*stack)->previous = new;
new->next = *stack;
}
}
void stack_add_front(t_stack **stack, t_stack *new)
{
if (!stack || !new)
return ;
stack_add_back(stack, new);
*stack = new;
}