-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpivot.c
34 lines (31 loc) · 1.19 KB
/
pivot.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pivot.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/08 18:11:41 by jjacobso #+# #+# */
/* Updated: 2019/02/08 18:51:01 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
int get_pivot(t_list *a, size_t len)
{
int *m;
t_list *t;
size_t i;
int res;
i = 0;
t = a;
EXITIF(!(m = (int *)malloc(sizeof(int) * l_size(a))));
while (t && i < len)
{
m[i++] = DATA(t);
t = t->next;
}
int_bubble_sort(m, i);
res = m[i / 2];
free(m);
return (res);
}