From e1fa1b58e876cc452b03b2f41540cefc976bed90 Mon Sep 17 00:00:00 2001 From: rask24 Date: Tue, 23 Jan 2024 15:50:01 +0900 Subject: [PATCH] implement wrapper clear_stack --- Makefile | 3 ++- include/push_swap.h | 3 ++- src/main.c | 4 ++-- src/utils/clear_stack.c | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/utils/clear_stack.c diff --git a/Makefile b/Makefile index 3f9b214..42951ea 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,8 @@ SRC = $(SRC_DIR)/main.c \ $(SRC_DIR)/stack_operations/ft_lst_before.c \ $(SRC_DIR)/utils/first_content.c \ $(SRC_DIR)/utils/second_content.c \ - $(SRC_DIR)/utils/exit_with_error.c + $(SRC_DIR)/utils/exit_with_error.c \ + $(SRC_DIR)/utils/clear_stack.c OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC)) DEP = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.d, $(SRC)) OBJ_FILTER_MAIN = $(filter-out $(BUILD_DIR)/main.o, $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC))) diff --git a/include/push_swap.h b/include/push_swap.h index f2bbe5c..e6e5f70 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -6,7 +6,7 @@ /* By: reasuke +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/10 12:37:54 by reasuke #+# #+# */ -/* Updated: 2024/01/23 15:25:01 by reasuke ### ########.fr */ +/* Updated: 2024/01/23 15:51:40 by reasuke ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,5 +48,6 @@ t_list *ft_lst_before(t_list *lst, t_list *trg); int first_content(t_stack **p_stack); int second_content(t_stack **p_stack); void exit_with_error(void); +void clear_stack(t_stack **p_stack, void (*del)(void *)); #endif diff --git a/src/main.c b/src/main.c index c67c09b..c9d6e12 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: reasuke +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/10 12:37:36 by reasuke #+# #+# */ -/* Updated: 2024/01/23 15:33:21 by reasuke ### ########.fr */ +/* Updated: 2024/01/23 15:48:43 by reasuke ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,6 +41,6 @@ int main(int argc, char **argv) a = generate_stack(argc, argv); b = NULL; sort(&a, &b, argc - 1); - ft_lstclear(&a, free); + clear_stack(&a, free); return (0); } diff --git a/src/utils/clear_stack.c b/src/utils/clear_stack.c new file mode 100644 index 0000000..9dfee44 --- /dev/null +++ b/src/utils/clear_stack.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* clear_stack.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: reasuke +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/01/23 15:46:24 by reasuke #+# #+# */ +/* Updated: 2024/01/23 15:47:39 by reasuke ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "push_swap.h" + +void clear_stack(t_stack **p_stack, void (*del)(void *)) +{ + ft_lstclear(p_stack, del); +}