-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_operations_bis.c
executable file
·72 lines (63 loc) · 1.57 KB
/
ft_operations_bis.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_operations_bis.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abadidi < abadidi@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/11 18:38:03 by abadidi #+# #+# */
/* Updated: 2021/12/12 01:04:35 by abadidi ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void push(t_stack **s, int val)
{
t_stack *new;
new = malloc(sizeof(t_stack));
if (new)
{
ft_bzero(new, sizeof(t_stack));
new->val = val;
new->next = *s;
*s = new;
}
}
int pop(t_stack **s)
{
t_stack *tmp;
int val;
if (s && *s)
{
tmp = *s;
*s = (*s)->next;
val = tmp->val;
free(tmp);
tmp = NULL;
return (val);
}
return (0);
}
int peak(t_stack *s)
{
if (s)
return (s->val);
return (0);
}
void swap(t_stack *s)
{
t_stack *second;
int tmp;
if (s == NULL)
return ;
second = s->next;
if (second == NULL)
return ;
tmp = s->val;
s->val = second->val;
second->val = tmp;
}
int push_from(t_stack **a, t_stack **b)
{
push(a, pop(b));
return (1);
}