push_swap/srcs/ps_swap.c
Tanguy MAZE 428525b561 Nearly there !!!
WIP merge sort
still problems with negative numbers
2019-03-06 12:12:00 +01:00

43 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ps_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/21 14:06:40 by tmaze #+# #+# */
/* Updated: 2019/03/06 12:02:03 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ps_swap(t_psdata *data, char c)
{
t_stack **s;
size_t size;
t_stack *tmp;
if (c == 'a')
s = &(data->a);
if (c == 'a')
size = data->size_a;
else if (c == 'b')
s = &(data->b);
if (c == 'b')
size = data->size_b;
if (s != NULL && size >= 2)
{
tmp = *s;
*s = (*s)->next;
tmp->next = (*s)->next;
(*s)->next = tmp;
}
}
void ps_sswap(t_psdata *data)
{
ps_swap(data, 'a');
ps_swap(data, 'b');
}