-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_sorted.c
37 lines (34 loc) · 1.35 KB
/
is_sorted.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_sorted.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlucio-l <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/30 23:19:32 by rlucio-l #+# #+# */
/* Updated: 2022/05/30 23:20:18 by rlucio-l ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int is_sorted(t_node *stack_head)
{
t_node *compared_node;
t_node *node;
compared_node = stack_head->next;
node = compared_node->next;
while (compared_node->next != stack_head)
{
while (node->next != stack_head)
{
if (compared_node->element > node->element)
return (0);
else
node = node->next;
}
if (compared_node->element > node->element)
return (0);
compared_node = compared_node->next;
node = compared_node->next;
}
return (1);
}