Push the final version
This commit is contained in:
commit
d0fe1fb2fb
28 changed files with 1459 additions and 0 deletions
56
sources/push.c
Executable file
56
sources/push.c
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* push.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/13 12:08:03 by rparodi #+# #+# */
|
||||
/* Updated: 2024/03/06 11:55:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/push_swap.h"
|
||||
|
||||
static int push(t_list **stack_to, t_list **stack_from)
|
||||
{
|
||||
t_list *tmp;
|
||||
t_list *head_to;
|
||||
t_list *head_from;
|
||||
|
||||
if (ft_lstsize(*stack_from) == 0)
|
||||
return (-1);
|
||||
head_to = *stack_to;
|
||||
head_from = *stack_from;
|
||||
tmp = head_from;
|
||||
head_from = head_from->next;
|
||||
*stack_from = head_from;
|
||||
if (!head_to)
|
||||
{
|
||||
head_to = tmp;
|
||||
head_to->next = NULL;
|
||||
*stack_to = head_to;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp->next = head_to;
|
||||
*stack_to = tmp;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pa(t_list **stack_a, t_list **stack_b)
|
||||
{
|
||||
if (push(stack_a, stack_b) == -1)
|
||||
return (-1);
|
||||
write(1, "pa\n", 3);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int pb(t_list **stack_a, t_list **stack_b)
|
||||
{
|
||||
if (push(stack_b, stack_a) == -1)
|
||||
return (-1);
|
||||
write(1, "pb\n", 3);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue