hewow owo
added header, libft and all basic interactions with stack
This commit is contained in:
21
srcs/ps_push.c
Normal file
21
srcs/ps_push.c
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ps_push.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/21 15:59:46 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/21 16:06:04 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ps_push(t_stack **s1, t_stack **s2)
|
||||
{
|
||||
t_stack *tmp;
|
||||
|
||||
tmp = ps_stkpop(s2);
|
||||
ps_stkpsh(s1, tmp);
|
||||
}
|
40
srcs/ps_rerot.c
Normal file
40
srcs/ps_rerot.c
Normal file
@@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ps_rerot.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/21 16:32:04 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/21 16:38:13 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ps_rerot(t_stack **s)
|
||||
{
|
||||
t_stack *prec;
|
||||
t_stack *tmp;
|
||||
|
||||
if (*s != NULL && ps_stksize(*s) > 2)
|
||||
{
|
||||
prec = *s;
|
||||
tmp = (*s)->next;
|
||||
while (tmp->next != NULL)
|
||||
{
|
||||
tmp = tmp->next;
|
||||
prec = prec->next;
|
||||
}
|
||||
prec->next = NULL;
|
||||
ps_stkpsh(s, tmp);
|
||||
}
|
||||
else if (*s != NULL && ps_stksize(*s) == 2)
|
||||
ps_swap(s);
|
||||
}
|
||||
|
||||
void ps_rrerot(t_stack **a, t_stack **b)
|
||||
{
|
||||
ps_rerot(a);
|
||||
ps_rerot(b);
|
||||
}
|
36
srcs/ps_rot.c
Normal file
36
srcs/ps_rot.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ps_rot.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/21 16:07:55 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/21 16:26:22 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ps_rot(t_stack **s)
|
||||
{
|
||||
t_stack *tmp;
|
||||
t_stack *ind;
|
||||
|
||||
if (*s != NULL && ps_stksize(*s) > 2)
|
||||
{
|
||||
tmp = ps_stkpop(s);
|
||||
ind = *s;
|
||||
while (ind->next != NULL)
|
||||
ind = ind->next;
|
||||
ind->next = tmp;
|
||||
}
|
||||
else if (*s != NULL && ps_stksize(*s) == 2)
|
||||
ps_swap(s);
|
||||
}
|
||||
|
||||
void ps_rrot(t_stack **a, t_stack **b)
|
||||
{
|
||||
ps_rot(a);
|
||||
ps_rot(b);
|
||||
}
|
31
srcs/ps_swap.c
Normal file
31
srcs/ps_swap.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ps_swap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/21 14:06:40 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/21 15:19:00 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "push_swap.h"
|
||||
|
||||
void ps_swap(t_stack **s)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
if (*s != NULL && ps_stksize(*s) >= 2)
|
||||
{
|
||||
tmp = (*s)->nb;
|
||||
(*s)->nb = (*s)->next->nb;
|
||||
(*s)->next->nb = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void ps_sswap(t_stack **a, t_stack **b)
|
||||
{
|
||||
ps_swap(a);
|
||||
ps_swap(b);
|
||||
}
|
Reference in New Issue
Block a user