-
Notifications
You must be signed in to change notification settings - Fork 0
/
lil_main.c
86 lines (76 loc) · 1.76 KB
/
lil_main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lil_main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zwalad <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 14:49:11 by zwalad #+# #+# */
/* Updated: 2022/03/23 22:29:53 by zwalad ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_swap *sub_three(t_swap *a)
{
push_three(a);
exit(1);
}
t_stacks *stack_init(t_stacks *p, char *argv[], int argc, int i)
{
int j;
if (argc >= 6)
{
p->tab = malloc(sizeof (int) * (argc - 1));
j = 0;
while (j < argc - 1)
{
p->tab[j] = ps_atoi(argv[i]);
i++;
j++;
}
}
p->a = ps_lstnew(0);
p->b = NULL;
return (p);
}
int le_index(int i, t_swap *a)
{
int j;
j = 0;
while (a != NULL)
{
if (a->stack == i)
return (j);
j++;
a = a->next;
}
return (j);
}
int low_find(t_swap *a)
{
int i;
i = a->stack;
while (a != NULL)
{
if (a->stack < i)
i = a->stack;
a = a->next;
}
return (i);
}
int check_sorted(t_stacks *p, int argc)
{
t_swap *tmp1;
t_swap *tmp;
if (argc == 1)
exit(1);
tmp = p->a;
while (tmp->next != NULL)
{
tmp1 = tmp->next;
if (tmp1->stack < tmp->stack)
return (0);
tmp = tmp->next;
}
return (1);
}