Push the final version

This commit is contained in:
Raphaël 2024-04-20 14:48:16 +02:00
commit d0fe1fb2fb
28 changed files with 1459 additions and 0 deletions

61
sources/swap.c Executable file
View file

@ -0,0 +1,61 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/13 12:08:09 by rparodi #+# #+# */
/* Updated: 2024/04/18 15:18:54 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/push_swap.h"
static int swap(t_list **stack)
{
t_list *head;
t_list *next;
int tmp_val;
int tmp_index;
if (ft_lstsize(*stack) < 2)
return (-1);
head = *stack;
next = head->next;
if (!head && !next)
error_message("Error swap", stack, NULL, NULL);
tmp_val = head->value;
tmp_index = head->index;
head->value = next->value;
head->index = next->index;
next->value = tmp_val;
next->index = tmp_index;
return (0);
}
int sa(t_list **stack_a)
{
if (swap(stack_a) == -1)
return (-1);
write(1, "sa\n", 3);
return (0);
}
int sb(t_list **stack_b)
{
if (swap(stack_b) == -1)
return (-1);
write(1, "sb\n", 3);
return (0);
}
int ss(t_list **stack_a, t_list **stack_b)
{
if ((ft_lstsize(*stack_a) < 2) || (ft_lstsize(*stack_b) < 2))
return (-1);
swap(stack_a);
swap(stack_b);
write(1, "ss\n", 3);
return (0);
}