-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.c
55 lines (50 loc) · 1.45 KB
/
checker.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checker.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nenvoy <nenvoy@student.21-school.ru> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/15 16:43:10 by nenvoy #+# #+# */
/* Updated: 2021/12/15 16:44:45 by nenvoy ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int check_repeat(t_list *node)
{
t_list *search;
while (node)
{
search = node;
while (search)
{
if ((node->data == search->data)
&& (node->index != search->index))
return (-1);
search = search->next;
}
node = node->next;
}
return (0);
}
int check_sort(t_list *node)
{
while (node->next != NULL)
{
if (node->data > node->next->data)
return (0);
node = node->next;
}
return (-1);
}
int check(t_list *node)
{
if (check_sort(node))
exit (0);
if (check_repeat(node))
{
write(2, "Error\n", 6);
exit (0);
}
return (0);
}