-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpushing.c
52 lines (46 loc) · 1.67 KB
/
pushing.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pushing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lstorey <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/20 09:03:27 by lstorey #+# #+# */
/* Updated: 2024/03/23 22:04:42 by lstorey ### ########.fr */
/* */
/* ************************************************************************** */
/* ************************************* */
/* pa - push to A. top elements to A */
/* pb - push to B. top elements to B */
/* ************************************* */
#include "push_swap.h"
static void push(t_ps_list **src_list, t_ps_list **dest_list)
{
t_ps_list *top_src;
t_ps_list *top_dest;
t_ps_list *sec_src;
if (!src_list)
return ;
top_src = (*src_list);
top_dest = (*dest_list);
if (top_src->next == NULL)
sec_src = NULL;
else
sec_src = top_src->next;
if (!*dest_list)
top_src->next = NULL;
else
top_src->next = top_dest;
(*dest_list) = top_src;
(*src_list) = sec_src;
}
void pa(t_ps_list **stack_a, t_ps_list **stack_b)
{
push(stack_b, stack_a);
ft_printf("pa\n");
}
void pb(t_ps_list **stack_a, t_ps_list **stack_b)
{
push(stack_a, stack_b);
ft_printf("pb\n");
}