-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_swaping.c
62 lines (56 loc) · 1.88 KB
/
ft_swaping.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swaping.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sconso <sconso@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2013/12/24 16:46:01 by sconso #+# #+# */
/* Updated: 2013/12/27 22:59:13 by sconso ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_pushswap.h"
char *ft_sa(t_control **list)
{
t_l_a *tmp;
if (!list || !*list)
ft_exit("Error\n");
if ((*list)->firsta != (*list)->lasta)
{
tmp = (*list)->firsta;
(*list)->firsta = (*list)->firsta->next;
(*list)->firsta->next->prev = tmp;
tmp->next = (*list)->firsta->next;
tmp->prev = (*list)->firsta;
(*list)->firsta->next = tmp;
(*list)->firsta->prev = (*list)->lasta;
(*list)->lasta->next = (*list)->firsta;
}
return ("sa");
}
char *ft_sb(t_control **list)
{
t_l_a *tmp;
if (!list || !*list)
ft_exit("Error\n");
if ((*list)->firstb != (*list)->lastb)
{
tmp = (*list)->firstb;
(*list)->firstb = (*list)->firstb->next;
(*list)->firstb->next->prev = tmp;
tmp->next = (*list)->firstb->next;
tmp->prev = (*list)->firstb;
(*list)->firstb->next = tmp;
(*list)->firstb->prev = (*list)->lastb;
(*list)->lastb->next = (*list)->firstb;
}
return ("sb");
}
char *ft_ss(t_control **list)
{
if (!list || !*list)
ft_exit("Error\n");
ft_sa(list);
ft_sb(list);
return ("ss");
}