]> www.ljiriste.work Git - Libft.git/commitdiff
Compress ft_stack into a single file
authorLukáš Jiřiště <redacted>
Mon, 6 Apr 2026 11:04:40 +0000 (13:04 +0200)
committerLukáš Jiřiště <redacted>
Mon, 6 Apr 2026 11:04:40 +0000 (13:04 +0200)
Makefile
ft_struct/ft_stack.c [new file with mode: 0644]
ft_struct/ft_stack_free.c [deleted file]
ft_struct/ft_stack_init.c [deleted file]
ft_struct/ft_stack_pop.c [deleted file]
ft_struct/ft_stack_push.c [deleted file]
ft_struct/ft_stack_top.c [deleted file]

index ae3499395e65ced151ff2dcc84ef9463df17e2ae..b1586674e9bb4999bef110fe1a0e20dd1c43215f 100644 (file)
--- 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 (file)
index 0000000..f41530a
--- /dev/null
@@ -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 (file)
index d057d6b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ************************************************************************** */
-/*                                                                            */
-/*                                                        :::      ::::::::   */
-/*   ft_stack_free.c                                    :+:      :+:    :+:   */
-/*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
-/*                                                +#+#+#+#+#+   +#+           */
-/*   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 (file)
index 3f7feac..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/* ************************************************************************** */
-/*                                                                            */
-/*                                                        :::      ::::::::   */
-/*   ft_stack_init.c                                    :+:      :+:    :+:   */
-/*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
-/*                                                +#+#+#+#+#+   +#+           */
-/*   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 <sys/types.h>
-
-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 (file)
index a9db28c..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ************************************************************************** */
-/*                                                                            */
-/*                                                        :::      ::::::::   */
-/*   ft_stack_pop.c                                     :+:      :+:    :+:   */
-/*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
-/*                                                +#+#+#+#+#+   +#+           */
-/*   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 (file)
index db72c04..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* ************************************************************************** */
-/*                                                                            */
-/*                                                        :::      ::::::::   */
-/*   ft_stack_push.c                                    :+:      :+:    :+:   */
-/*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
-/*                                                +#+#+#+#+#+   +#+           */
-/*   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 (file)
index be7a55a..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-/* ************************************************************************** */
-/*                                                                            */
-/*                                                        :::      ::::::::   */
-/*   ft_stack_top.c                                     :+:      :+:    :+:   */
-/*                                                    +:+ +:+         +:+     */
-/*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
-/*                                                +#+#+#+#+#+   +#+           */
-/*   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 <stddef.h>
-
-void   *ft_stack_top(t_stack *stack)
-{
-       if (!stack->list.head)
-               return (NULL);
-       return (ft_llist_access(stack->list.head));
-}