-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort_utils.c
65 lines (58 loc) · 1.66 KB
/
sort_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sort_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zhlim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/07 09:26:45 by zhlim #+# #+# */
/* Updated: 2023/08/10 01:29:28 by zhlim ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int get_number(t_content *content)
{
return (content->number);
}
int get_index(t_content *content)
{
return (content->index);
}
int check_sorted(t_list *stack_a)
{
int a;
int b;
while (stack_a)
{
if (stack_a->next)
{
a = get_number(stack_a->content);
b = get_number(stack_a->next->content);
if (a > b)
return (0);
}
stack_a = stack_a->next;
}
return (1);
}
int smallest_pos(t_list *stack, int size)
{
t_op op;
init_op(&op);
op.smallest = get_number(stack->content);
op.small_index = op.i;
while (stack)
{
if (get_number(stack->content) < op.smallest)
{
op.smallest = get_number(stack->content);
op.small_index = op.i;
}
op.i++;
stack = stack->next;
}
if (op.small_index < (size / 2) + 1)
return (1);
else
return (0);
}