-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs.c
108 lines (99 loc) · 2.37 KB
/
funcs.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* funcs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vsosevic <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/17 16:41:18 by vsosevic #+# #+# */
/* Updated: 2017/03/17 16:41:33 by vsosevic ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int stk_a_is_sorted(t_stack *a, int n)
{
int i;
int res;
i = 0;
res = 1;
while (i < a->nbrs_l - 1 && i < n - 1)
{
if (a->nbrs[i] > a->nbrs[i + 1])
return (0);
i++;
}
return (res);
}
int stk_b_is_sorted(t_stack *b, int n)
{
int i;
int res;
i = 0;
res = 1;
while (i < b->nbrs_l - 1 && i < n - 1)
{
if (b->nbrs[i] < b->nbrs[i + 1])
return (0);
i++;
}
return (res);
}
int *nbrs_from_argv(char **argv, int n)
{
int i;
int j;
int *nbrs;
i = 0;
nbrs = (int *)malloc(sizeof(int) * n);
while (i < n)
{
nbrs[i] = ft_atoi_modified(argv[i + 1]);
j = i;
while (j > 0)
if (nbrs[--j] == nbrs[i])
ft_exit("\x1B[31mError\n\x1B[33mDuplicates in the list");
i++;
}
return (nbrs);
}
void create_stacks(int *nbrs, int nbrs_len, t_stack *a, t_stack *b)
{
int i;
a->nbrs = (int *)malloc(sizeof(int) * nbrs_len);
a->nbrs_l = nbrs_len;
a->name = 'a';
i = 0;
while (i < nbrs_len)
{
a->nbrs[i] = nbrs[i];
i++;
}
b->nbrs = (int *)malloc(sizeof(int) * nbrs_len);
b->nbrs_l = 0;
b->name = 'b';
}
/*
**void print_stacks(t_stack *a, t_stack *b, int argc)
**{
** int i;
** int n;
**
** i = 0;
** printf("_____________________\n");
** printf("| Stack A | Stack B |\n");
** printf("---------------------\n");
** while (i < argc - 1)
** {
** if (i < a->nbrs_l)
** printf("| %4d |", a->nbrs[i]);
** else
** printf("|%9s|", " ");
** if (i < b->nbrs_l)
** printf(" %4d |", b->nbrs[i]);
** else
** printf("%9s|", " ");
** printf("\n");
** i++;
** }
**}
*/