-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop_push.c
41 lines (36 loc) · 1.33 KB
/
pop_push.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pop_push.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atoof <atoof@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 17:31:36 by atoof #+# #+# */
/* Updated: 2023/04/11 17:31:36 by atoof ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int pop(t_node **stack)
{
t_node *top_node;
int data;
if (!*stack)
return (0);
top_node = *stack;
data = top_node->data;
*stack = top_node->next;
free(top_node);
return (data);
}
void push(int data, t_node **stack)
{
t_node *new_node;
new_node = create_node(data);
if (!new_node)
return ;
if (!*stack)
new_node->next = NULL;
else
new_node->next = *stack;
*stack = new_node;
}