mirror of
https://github.com/DavidGailleton/42-Push_Swap.git
synced 2026-01-27 08:41:58 +00:00
Merge branch 'stack_functions'
This commit is contained in:
54
stack_utils/stack_add.c
Normal file
54
stack_utils/stack_add.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack_add.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
23
stack_utils/stack_remove.c
Normal file
23
stack_utils/stack_remove.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* stack_remove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: dgaillet <dgaillet@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user