-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.c
More file actions
53 lines (48 loc) · 1.48 KB
/
push.c
File metadata and controls
53 lines (48 loc) · 1.48 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctacconi <ctacconi@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/18 18:51:41 by ctacconi #+# #+# */
/* Updated: 2024/04/25 16:33:11 by ctacconi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void pa(t_stack *src, t_stack *dst)
{
write(1, "pa\n", 3);
move_push(src, dst);
}
void pb(t_stack *src, t_stack *dst)
{
write(1, "pb\n", 3);
move_push(src, dst);
}
void move_push(t_stack *src, t_stack *dst)
{
t_element *tmp;
t_element *tmp2;
if (src->len < 1)
return ;
if (dst->first == NULL)
{
tmp = src->first;
src->first = src->first->next;
dst->first = tmp;
dst->first->next = NULL;
src->len--;
dst->len++;
}
else
{
tmp2 = dst->first;
tmp = src->first;
src->first = src->first->next;
dst->first = tmp;
dst->first->next = tmp2;
src->len--;
dst->len++;
}
}