-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.c
More file actions
65 lines (59 loc) · 1.64 KB
/
Copy pathpush.c
File metadata and controls
65 lines (59 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hceviz <hceviz@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/21 11:21:39 by hceviz #+# #+# */
/* Updated: 2025/02/24 09:25:45 by hceviz ### ########.fr */
/* */
/* ************************************************************************** */
#include "pushswap.h"
void set_connections(t_stack *node, t_stack **to)
{
if (!*to)
{
*to = node;
node->next = node;
node->prev = node;
}
else
{
node->prev = (*to)->prev;
node->next = *to;
(*to)->prev->next = node;
(*to)->prev = node;
*to = node;
}
}
void push(t_stack **from, t_stack **to)
{
t_stack *node;
if (!*from)
return ;
node = *from;
*from = (*from)->next;
if (*from == node)
*from = NULL;
else
{
(*from)->prev = node->prev;
node->prev->next = *from;
}
set_connections(node, to);
update_index(*to);
update_index(*from);
}
void pa(t_stack **b, t_stack **a, bool print)
{
push(b, a);
if (print == true)
ft_putstr("pa\n");
}
void pb(t_stack **a, t_stack **b, bool print)
{
push(a, b);
if (print == true)
ft_putstr("pb\n");
}