-
Notifications
You must be signed in to change notification settings - Fork 0
/
whole_list_checks.c
67 lines (61 loc) · 1.63 KB
/
whole_list_checks.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* whole_list_checks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgober <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 11:45:04 by pgober #+# #+# */
/* Updated: 2023/11/05 11:47:21 by pgober ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int list_len(t_stack *head)
{
int i;
if (!head)
return (0);
i = 0;
while (head)
{
i++;
head = head->next;
}
return (i);
}
int correct_list1(t_stack *list, int len)
{
if (list_len(list) != len)
return (0);
while (list->next)
{
if (*((int *)(list->next)->data) < *((int *)list->data))
return (0);
list = list->next;
}
return (1);
}
int descending1(t_stack *list)
{
if (!list)
return (-1);
while (list->next)
{
if (*((int *)list->data) < *((int *)(list->next)->data))
return (0);
list = list->next;
}
return (1);
}
int ascending(t_stack *list)
{
if (!list)
return (-1);
while (list->next)
{
if (*((int *)(list->next)->data) < *((int *)list->data))
return (0);
list = list->next;
}
return (1);
}