From 8e1bbe674c117e6203a23162bd3bd307a6eff0a2 Mon Sep 17 00:00:00 2001 From: David Gailleton Date: Mon, 8 Dec 2025 16:16:23 +0100 Subject: [PATCH] rename stack_functions folder to stack_utils + add stack add and stack remove functions --- stack_functions/.gitkeep | 0 {stack_functions => stack_utils}/push.c | 0 {stack_functions => stack_utils}/rev_rotate.c | 0 {stack_functions => stack_utils}/rotate.c | 0 stack_utils/stack_add.c | 54 +++++++++++++++++++ stack_utils/stack_remove.c | 23 ++++++++ {stack_functions => stack_utils}/swap.c | 0 7 files changed, 77 insertions(+) delete mode 100644 stack_functions/.gitkeep rename {stack_functions => stack_utils}/push.c (100%) rename {stack_functions => stack_utils}/rev_rotate.c (100%) rename {stack_functions => stack_utils}/rotate.c (100%) create mode 100644 stack_utils/stack_add.c create mode 100644 stack_utils/stack_remove.c rename {stack_functions => stack_utils}/swap.c (100%) diff --git a/stack_functions/.gitkeep b/stack_functions/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/stack_functions/push.c b/stack_utils/push.c similarity index 100% rename from stack_functions/push.c rename to stack_utils/push.c diff --git a/stack_functions/rev_rotate.c b/stack_utils/rev_rotate.c similarity index 100% rename from stack_functions/rev_rotate.c rename to stack_utils/rev_rotate.c diff --git a/stack_functions/rotate.c b/stack_utils/rotate.c similarity index 100% rename from stack_functions/rotate.c rename to stack_utils/rotate.c diff --git a/stack_utils/stack_add.c b/stack_utils/stack_add.c new file mode 100644 index 0000000..9775452 --- /dev/null +++ b/stack_utils/stack_add.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack_add.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dgaillet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/12/08 15:52:40 by dgaillet #+# #+# */ +/* Updated: 2025/12/08 16:03:54 by dgaillet ### ########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)) + { + (*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; +} diff --git a/stack_utils/stack_remove.c b/stack_utils/stack_remove.c new file mode 100644 index 0000000..393b591 --- /dev/null +++ b/stack_utils/stack_remove.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* stack_remove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dgaillet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/12/08 16:05:27 by dgaillet #+# #+# */ +/* Updated: 2025/12/08 16:15:28 by dgaillet ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" +#include + +void stack_clear_all(t_stack *stack, t_stack *first) +{ + if (!stack) + return ; + if (stack->next != first) + stack_clear_all(stack->next, first); + free(stack); +} diff --git a/stack_functions/swap.c b/stack_utils/swap.c similarity index 100% rename from stack_functions/swap.c rename to stack_utils/swap.c