tgrekov-push_swap
HIVE push_swap July 2024
Loading...
Searching...
No Matches
is_sorted.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* is_sorted.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2024/07/15 08:05:56 by tgrekov #+# #+# */
9
/* Updated: 2024/07/17 08:31:35 by tgrekov ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
20
#include "../utils/utils.h"
21
#include "
stack.h
"
22
31
int
is_sorted
(
t_stack
*stack,
int
mode)
32
{
33
int
minix;
34
int
i;
35
36
minix =
get_minix
(stack[mode].n, stack[mode].len);
37
i = minix;
38
while
(1)
39
{
40
i = wrap_ix(i - (1 - 2 * mode), stack[mode].len);
41
if
(i == minix)
42
break ;
43
if
(stack[mode].n[wrap_ix(i - (1 - 2 * mode), stack[mode].len)]
44
> stack[mode].n[wrap_ix(i, stack[mode].len)])
45
return
(0);
46
}
47
return
(1);
48
}
get_minix
int get_minix(int *arr, int len)
Get the index of the smallest element.
Definition
get_minix.c:27
is_sorted
int is_sorted(t_stack *stack, int mode)
Check if the contents of a stack are in the correct order relative to the smallest element.
Definition
is_sorted.c:31
stack.h
s_stack
Definition
stack.h:24
src
mandatory
stack
is_sorted.c