-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsorting_utils.c
89 lines (78 loc) · 1.89 KB
/
sorting_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* :::::::: */
/* sorting_utils.c :+: :+: */
/* +:+ */
/* By: sramos <sramos@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2024/04/25 14:58:17 by sramos #+# #+# */
/* Updated: 2024/04/29 12:55:57 by sramos ######## odam.nl */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_node *find_pivot(t_node **stack_a, int count)
{
t_node *pivot;
pivot = *stack_a;
while (pivot)
{
if (pivot->index == (count / 2))
return (pivot);
pivot = pivot->next;
}
return (pivot);
}
int c_nodes(t_node *stack)
{
t_node *current;
int count;
current = stack;
count = 0;
while (current)
{
current = current->next;
count++;
}
return (count);
}
void set_group(t_node **stack_a)
{
t_node *current;
int i;
current = *stack_a;
i = 0;
while (current)
{
current->group = i;
current = current->next;
i++;
}
}
t_node *find_small(t_node **stack_a)
{
t_node *smallest;
t_node *current;
smallest = *stack_a;
current = (*stack_a)->next;
while (current)
{
if (current->n < smallest->n)
smallest = current;
current = current->next;
}
return (smallest);
}
t_node *find_bigger(t_node **stack_a)
{
t_node *temp;
t_node *bigger;
temp = *stack_a;
bigger = *stack_a;
while (temp)
{
if (temp->n > bigger->n)
bigger = temp;
temp = temp->next;
}
return (bigger);
}