-
Notifications
You must be signed in to change notification settings - Fork 1
/
swap.c
43 lines (38 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lburkins <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/16 14:24:44 by lburkins #+# #+# */
/* Updated: 2024/03/04 13:50:33 by lburkins ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
static void swap(t_node **stack)
{
t_node *new_top;
t_node *old_top;
if (!*stack || !(*stack)->next)
return ;
new_top = (*stack)->next;
old_top = *stack;
old_top->next = new_top->next;
if (new_top->next)
new_top->next->prev = old_top;
new_top->next = old_top;
old_top->prev = new_top;
new_top->prev = NULL;
*stack = new_top;
}
void sa(t_node **a)
{
swap(a);
ft_printf("sa\n");
}
void sb(t_node **b)
{
swap(b);
ft_printf("sb\n");
}