-
Notifications
You must be signed in to change notification settings - Fork 1
/
sort_functions.c
60 lines (55 loc) · 874 Bytes
/
sort_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
#include "push_swap.h"
void sort(int *array, int size)
{
int temp;
int i;
i = 0;
while (i < size)
{
if (array[i] > array[i + 1])
{
temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
i = -1;
}
i++;
}
}
int select_middle(int *array, t_ps *ps, int temp, int middle)
{
if (temp <= 100)
{
sort(array, ps->bottom_a + 1);
middle = (ps->bottom_a + 1) / 2;
middle = array[middle];
}
else
{
sort(array, temp);
ps->chunks = ps->chunks + (temp / 10);
middle = array[ps->chunks];
}
return (middle);
}
int bubble_sort(int *stack, t_ps *ps)
{
int middle;
int *array;
int temp;
int i;
int j;
i = 0;
j = 1;
temp = ps->size;
middle = 0;
array = ft_calloc(ps->size, sizeof(int *));
while (i <= temp)
{
array[i] = stack[i];
i++;
}
middle = select_middle(array, ps, temp, middle);
free(array);
return (middle);
}