54 lines
1.5 KiB
C
Executable file
54 lines
1.5 KiB
C
Executable file
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* rotate.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/02/13 12:08:07 by rparodi #+# #+# */
|
|
/* Updated: 2024/03/06 11:55:32 by rparodi ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../includes/push_swap.h"
|
|
|
|
static int rotate(t_list **stack)
|
|
{
|
|
t_list *head;
|
|
t_list *tail;
|
|
|
|
if (ft_lstsize(*stack) < 2)
|
|
return (-1);
|
|
head = *stack;
|
|
tail = ft_lstlast(head);
|
|
*stack = head->next;
|
|
head->next = NULL;
|
|
tail->next = head;
|
|
return (0);
|
|
}
|
|
|
|
int ra(t_list **stack_a)
|
|
{
|
|
if (rotate(stack_a) == -1)
|
|
return (-1);
|
|
write(1, "ra\n", 3);
|
|
return (0);
|
|
}
|
|
|
|
int rb(t_list **stack_b)
|
|
{
|
|
if (rotate(stack_b) == -1)
|
|
return (-1);
|
|
write(1, "rb\n", 3);
|
|
return (0);
|
|
}
|
|
|
|
int rr(t_list **stack_a, t_list **stack_b)
|
|
{
|
|
if ((ft_lstsize(*stack_a) < 2) || (ft_lstsize(*stack_b) < 2))
|
|
return (-1);
|
|
rotate(stack_a);
|
|
rotate(stack_b);
|
|
write(1, "rr\n", 3);
|
|
return (0);
|
|
}
|