Push_swap/srcs/stack.c

44 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <lfirmin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/12 19:00:13 by lfirmin #+# #+# */
/* Updated: 2024/11/03 18:08:42 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "../include/pushswap.h"
t_stack *init_stack(void)
{
t_stack *stack;
stack = malloc(sizeof(t_stack));
if (!stack)
{
return (NULL);
ft_printf_fd(2, "Error");
}
stack->top = NULL;
stack->size = 0;
return (stack);
}
void free_stack(t_stack *stack)
{
t_node *current;
t_node *next;
current = stack->top;
while (current)
{
next = current->next;
free(current);
current = next;
}
free(stack);
}