From: Lukáš Jiřiště Date: Mon, 6 Apr 2026 11:04:40 +0000 (+0200) Subject: Compress ft_stack into a single file X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=4eb1ca54a03ce22c0df9ce4531e5fad4b483d0c8;p=Libft.git Compress ft_stack into a single file --- diff --git a/Makefile b/Makefile index ae34993..b158667 100644 --- a/Makefile +++ b/Makefile @@ -15,11 +15,7 @@ INCLUDE := $(addprefix -I, $(INCDIR)) SRCDIR := ft_gen ft_math ft_str ft_mem ft_io ft_check ft_conv \ ft_lst ft_arr ft_parse ft_struct -SRCstruct:= ft_stack_free.c \ - ft_stack_init.c \ - ft_stack_pop.c \ - ft_stack_push.c \ - ft_stack_top.c \ +SRCstruct:= ft_stack.c \ ft_tree_init.c \ ft_tree_access_root.c \ ft_tree_append_child.c \ diff --git a/ft_struct/ft_stack.c b/ft_struct/ft_stack.c new file mode 100644 index 0000000..f41530a --- /dev/null +++ b/ft_struct/ft_stack.c @@ -0,0 +1,44 @@ +#include "ft_struct.h" + +t_ft_stat ft_stack_init(t_stack *stack, size_t el_size) +{ + return (ft_llist_init(&stack->list, el_size)); +} + +t_ft_stat ft_stack_push(t_stack *stack, void *element) +{ + t_llist_node *new_node; + + if (!stack || !element) + { + return (invalid_input); + } + new_node = ft_llist_insert_head(&stack->list, element); + if (!new_node) + { + return (alloc_fail); + } + return (success); +} + +void *ft_stack_top(t_stack *stack) +{ + if (!stack->list.head) + return (NULL); + return (ft_llist_access(stack->list.head)); +} + +void *ft_stack_pop(t_stack *stack) +{ + void *res; + + res = ft_stack_top(stack); + ft_llist_delete_head(&stack->list, NULL); + return (res); +} + +void ft_stack_free(t_stack *stack, void (*free_el)(void *)) +{ + ft_llist_free(&stack->list, free_el); + return ; +} diff --git a/ft_struct/ft_stack_free.c b/ft_struct/ft_stack_free.c deleted file mode 100644 index d057d6b..0000000 --- a/ft_struct/ft_stack_free.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stack_free.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/06/20 17:16:56 by ljiriste #+# #+# */ -/* Updated: 2024/06/20 17:18:38 by ljiriste ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_struct.h" -#include "ft_arr.h" - -void ft_stack_free(t_stack *stack, void (*free_el)(void *)) -{ - ft_llist_free(&stack->list, free_el); - return ; -} diff --git a/ft_struct/ft_stack_init.c b/ft_struct/ft_stack_init.c deleted file mode 100644 index 3f7feac..0000000 --- a/ft_struct/ft_stack_init.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stack_init.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/06/20 17:04:10 by ljiriste #+# #+# */ -/* Updated: 2024/06/20 17:47:14 by ljiriste ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_struct.h" -#include "ft_arr.h" -#include - -t_ft_stat ft_stack_init(t_stack *stack, size_t el_size) -{ - return (ft_llist_init(&stack->list, el_size)); -} diff --git a/ft_struct/ft_stack_pop.c b/ft_struct/ft_stack_pop.c deleted file mode 100644 index a9db28c..0000000 --- a/ft_struct/ft_stack_pop.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stack_pop.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/06/20 17:06:43 by ljiriste #+# #+# */ -/* Updated: 2024/06/20 17:47:27 by ljiriste ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_struct.h" -#include "ft_arr.h" - -void *ft_stack_pop(t_stack *stack) -{ - void *res; - - res = ft_stack_top(stack); - ft_llist_delete_head(&stack->list, NULL); - return (res); -} diff --git a/ft_struct/ft_stack_push.c b/ft_struct/ft_stack_push.c deleted file mode 100644 index db72c04..0000000 --- a/ft_struct/ft_stack_push.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stack_push.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/06/20 17:05:28 by ljiriste #+# #+# */ -/* Updated: 2024/06/20 17:47:51 by ljiriste ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_struct.h" -#include "ft_arr.h" - -t_ft_stat ft_stack_push(t_stack *stack, void *element) -{ - t_llist_node *new_node; - - if (!stack || !element) - { - return (invalid_input); - } - new_node = ft_llist_insert_head(&stack->list, element); - if (!new_node) - { - return (alloc_fail); - } - return (success); -} diff --git a/ft_struct/ft_stack_top.c b/ft_struct/ft_stack_top.c deleted file mode 100644 index be7a55a..0000000 --- a/ft_struct/ft_stack_top.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_stack_top.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ljiriste +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/06/20 17:11:34 by ljiriste #+# #+# */ -/* Updated: 2024/06/20 17:13:19 by ljiriste ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_struct.h" -#include "ft_arr.h" -#include - -void *ft_stack_top(t_stack *stack) -{ - if (!stack->list.head) - return (NULL); - return (ft_llist_access(stack->list.head)); -}