-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
66 lines (58 loc) · 1.56 KB
/
Copy pathstack.c
File metadata and controls
66 lines (58 loc) · 1.56 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
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alesferr <alesferr@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/07/20 18:44:49 by alesferr #+# #+# */
/* Updated: 2026/07/26 12:00:49 by alesferr ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void init_ps(t_ps *ps)
{
int i;
ps->a.v = NULL;
ps->b.v = NULL;
ps->bench = 0;
ps->quiet = 0;
ps->strat = ADAPTIVE;
ps->used = ADAPTIVE;
ps->disorder = 0;
i = 0;
while (i < 11)
ps->count[i++] = 0;
}
void st_init(t_ps *ps, t_stack *s, int cap)
{
s->v = malloc(sizeof(int) * cap);
if (!s->v)
error_exit(ps);
s->cap = cap;
s->top = 0;
s->size = 0;
}
int st_get(t_stack *s, int i)
{
return (s->v[(s->top + i) % s->cap]);
}
int is_sorted(t_stack *s)
{
int i;
i = 1;
while (i < s->size)
{
if (st_get(s, i - 1) > st_get(s, i))
return (0);
i++;
}
return (1);
}
void free_ps(t_ps *ps)
{
free(ps->a.v);
free(ps->b.v);
ps->a.v = NULL;
ps->b.v = NULL;
}