-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperations_push.c
More file actions
47 lines (40 loc) · 1.38 KB
/
operations_push.c
File metadata and controls
47 lines (40 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* operations_push.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: miissa <miissa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/31 11:27:59 by miissa #+# #+# */
/* Updated: 2026/01/05 13:07:42 by miissa ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static int can_push(t_stack *s)
{
return (s && s->size > 0);
}
static t_node *take_node(t_stack *s)
{
if (!can_push(s))
return (NULL);
return (stack_pop_front(s));
}
static void op_push(t_stack *src, t_stack *dest)
{
t_node *temp;
temp = take_node(src);
if (!temp)
return ;
stack_push_front(dest, temp);
}
void pa(t_stack *a, t_stack *b, t_ctx *ctx)
{
op_push(b, a);
ps_emit_op(ctx, OP_PA);
}
void pb(t_stack *a, t_stack *b, t_ctx *ctx)
{
op_push(a, b);
ps_emit_op(ctx, OP_PB);
}