-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorters.c
74 lines (67 loc) · 1.77 KB
/
sorters.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sorters.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cgleason <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/08/04 14:49:24 by cgleason #+# #+# */
/* Updated: 2018/08/08 14:42:19 by cgleason ### ########.fr */
/* */
/* ************************************************************************** */
#include "swap_push.h"
int stck_len(t_dblstck *stck)
{
int i;
t_dblstck *top;
top = stck;
if (top == NULL)
return (0);
stck = stck->next;
i = 1;
while (stck != top)
{
stck = stck->next;
i++;
}
return (i);
}
t_bool subset_issorted(t_dblstck *stck, int n, t_bool rev)
{
int i;
i = 1;
while (i < n)
{
if ((stck->next->num < stck->num && !rev) ||
(stck->next->num > stck->num && rev))
return (falsch);
i++;
stck = stck->next;
}
return (wahr);
}
int stck_issorted(t_dblstck *astck, t_dblstck *bstck)
{
void *begin;
if (bstck != NULL)
{
ft_putendl("KO");
free_stck(&astck);
free_stck(&bstck);
return (falsch);
}
begin = &(*astck);
while ((void *)(astck->next) != begin)
{
if (astck->next->num < astck->num)
{
ft_putendl("KO");
free_stck(&astck);
return (falsch);
}
astck = astck->next;
}
ft_putendl("OK");
free_stck(&astck);
return (wahr);
}