hewow owo
added header, libft and all basic interactions with stack
This commit is contained in:
commit
26f2acfcad
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "libft"]
|
||||
path = libft
|
||||
url = https://github.com/tvdu29/libft.git
|
40
includes/push_swap.h
Normal file
40
includes/push_swap.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* push_swap.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/21 14:13:53 by tmaze #+# #+# */
|
||||
/* Updated: 2019/02/21 16:05:33 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef PUSH_SWAP_H
|
||||
# define PUSH_SWAP_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include "libft.h"
|
||||
|
||||
typedef struct s_stack
|
||||
{
|
||||
int nb;
|
||||
struct s_stack *next;
|
||||
} t_stack;
|
||||
|
||||
t_stack *ps_stknew(int nb);
|
||||
void *ps_stkpsh(t_stack **s, t_stack *new);
|
||||
t_stack *ps_stkpop(t_stack **s);
|
||||
|
||||
size_t ps_stksize(t_stack *s);
|
||||
|
||||
void ps_swap(t_stack **s);
|
||||
void ps_sswap(t_stack **a, t_stack **b);
|
||||
void ps_push(t_stack **s1, t_stack **s2);
|
||||
void ps_rot(t_stack **s);
|
||||
void ps_rrot(t_stack **a, t_stack **b);
|
||||
void ps_rerot(t_stack **s);
|
||||
void ps_rrerot(t_stack **a, t_stack **b);
|
||||
|
||||
#endif
|
1
libft
Submodule
1
libft
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 4b44c49fc6caa15379cd821f967e53462d4dc837
|
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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user