-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_functions.c
94 lines (83 loc) · 1.98 KB
/
helper_functions.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* helper_functions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atoof <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 17:32:03 by atoof #+# #+# */
/* Updated: 2023/04/11 17:32:03 by atoof ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void ft_free_str_array(char **str_array)
{
int i;
i = 0;
while (str_array[i])
{
free(str_array[i]);
i++;
}
free(str_array);
str_array = NULL;
return ;
}
int is_sorted(t_node **stack)
{
t_node *tmp;
tmp = *stack;
while (tmp->next != NULL)
{
if (tmp->data < tmp->next->data)
tmp = tmp->next;
else
return (-1);
}
return (1);
}
int search_for_smallest_index(t_node **stack_a)
{
t_node *tmp;
int smallest;
int index;
int i;
smallest = INT_MAX;
index = 0;
i = 0;
tmp = *stack_a;
while (tmp != NULL)
{
if (tmp->data < smallest)
{
smallest = tmp->data;
index = i;
}
tmp = tmp->next;
i++;
}
return (index);
}
int ft_lstsize(t_node *stack)
{
int size;
size = 0;
while (stack != NULL)
{
stack = stack->next;
size++;
}
return (size);
}
int get_max_value(t_node *stack)
{
int max_value;
max_value = stack->data;
while (stack != NULL)
{
if (stack->data > max_value)
max_value = stack->data;
stack = stack->next;
}
return (max_value);
}