/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* stack_add.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: dgaillet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/08 15:52:40 by dgaillet #+# #+# */ /* Updated: 2025/12/09 08:51:33 by mteriier ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include "../push_swap.h" #include 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; }