-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswap.c
46 lines (40 loc) · 1.31 KB
/
swap.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amtadevo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/22 16:56:24 by amtadevo #+# #+# */
/* Updated: 2022/11/22 16:56:26 by amtadevo ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void swap(t_stack *top)
{
int tmp;
if (top == NULL || top->next == NULL)
return ;
tmp = top->data;
top->data = top->next->data;
top->next->data = tmp;
tmp = top->pos;
top->pos = top->next->pos;
top->next->pos = tmp;
}
void ss(t_stack *a, t_stack *b)
{
swap(a);
swap(b);
write(1, "ss\n", 3);
}
void sa(t_stack *a)
{
swap(a);
write(1, "sa\n", 3);
}
void sb(t_stack *b)
{
swap(b);
write(1, "sb\n", 3);
}