-
Notifications
You must be signed in to change notification settings - Fork 1
/
checkers.c
106 lines (96 loc) · 1.25 KB
/
checkers.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
#include "push_swap.h"
int check_order(int *stack_a, t_ps *ps)
{
int i;
i = 0;
while (i < ps->size - 1)
{
if (stack_a[i] > stack_a[i + 1])
return (0);
i++;
}
return (1);
}
int check_digit(char **argv)
{
int i;
int j;
i = 1;
while (argv[i])
{
j = 0;
while (argv[i][j])
{
if (argv[i][j] == '-')
j++;
if (ft_isdigit(argv[i][j]) == 0)
{
write(1, "Error\n", 7);
return (-1);
}
j++;
}
i++;
}
return (0);
}
int check_res(int *stack_a, t_ps *ps, int middle)
{
int i;
i = 0;
while (i <= ps->bottom_a)
{
if (stack_a[i] < middle)
{
ps->pos = i;
return (1);
}
i++;
}
return (0);
}
int check_bigger(int *stack, t_ps *ps)
{
int i;
int big;
i = ps->top_b;
big = -2147483647;
while (i < ps->size)
{
if (big < stack[i])
big = stack[i];
i++;
}
i = ps->top_b;
while (i < ps->size)
{
if (big == stack[i])
return (i);
i++;
}
return (0);
}
int check_dup(char **argv)
{
int i;
int j;
i = 1;
while (argv[i])
{
j = i + 1;
while (argv[j])
{
if (ft_strlen(argv[i]) == ft_strlen(argv[j]))
{
if (ft_strncmp(argv[i], argv[j], ft_strlen(argv[i])) == 0)
{
write(1, "\033[1;31mError\e[0m \U0001F92C\n", 23);
return (-1);
}
}
j++;
}
i++;
}
return (0);
}