Push the final version
This commit is contained in:
commit
d0fe1fb2fb
28 changed files with 1459 additions and 0 deletions
62
sources/reverse.c
Executable file
62
sources/reverse.c
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* reverse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/13 12:08:06 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/06 11:55:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/push_swap.h"
|
||||
|
||||
static int reverse(t_list **stack)
|
||||
{
|
||||
t_list *head;
|
||||
t_list *tail;
|
||||
|
||||
if (ft_lstsize(*stack) < 2)
|
||||
return (-1);
|
||||
head = *stack;
|
||||
tail = ft_lstlast(head);
|
||||
while (head)
|
||||
{
|
||||
if (head->next->next == NULL)
|
||||
{
|
||||
head->next = NULL;
|
||||
break ;
|
||||
}
|
||||
head = head->next;
|
||||
}
|
||||
tail->next = *stack;
|
||||
*stack = tail;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int rra(t_list **stack_a)
|
||||
{
|
||||
if (reverse(stack_a) == -1)
|
||||
return (-1);
|
||||
write(1, "rra\n", 4);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int rrb(t_list **stack_b)
|
||||
{
|
||||
if (reverse(stack_b) == -1)
|
||||
return (-1);
|
||||
write(1, "rrb\n", 4);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int rrr(t_list **stack_a, t_list **stack_b)
|
||||
{
|
||||
if ((ft_lstsize(*stack_a) < 2) || (ft_lstsize(*stack_b) < 2))
|
||||
return (-1);
|
||||
reverse(stack_a);
|
||||
reverse(stack_b);
|
||||
write(1, "rrr\n", 4);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue