-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils_for_utils.c
More file actions
66 lines (60 loc) · 1.56 KB
/
utils_for_utils.c
File metadata and controls
66 lines (60 loc) · 1.56 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_for_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: opopov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/20 16:59:11 by opopov #+# #+# */
/* Updated: 2025/03/26 13:36:33 by opopov ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
void small_to_top(t_stack **a)
{
while ((*a)->value != find_smallest(*a)->value)
{
if (find_smallest(*a)->is_below_medium == 0)
ra(a, 1);
else
rra(a, 1);
}
}
int stack_sorted(t_stack *stack)
{
if (!stack)
return (1);
while (stack->next)
{
if (stack->value > stack->next->value)
return (1);
stack = stack->next;
}
return (0);
}
void free_stack(t_stack **stack)
{
t_stack *current = *stack;
t_stack *next;
if (!stack)
return ;
while (current)
{
next = current->next;
free(current);
current = next;
}
*stack = NULL;
}
int count_stacks(t_stack *st)
{
if (!st)
return (0);
int i = 0;
while (st)
{
st = st->next;
i++;
}
return (i);
}