-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_sort_list.c
39 lines (36 loc) · 1.42 KB
/
ft_sort_list.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igarbuz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 17:34:28 by igarbuz #+# #+# */
/* Updated: 2018/11/18 23:06:19 by igarbuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_sort_list(t_list *lst, int (*cmp)(int, int))
{
t_list *tmplst;
void *tmpvoid;
size_t tmpint;
tmplst = lst;
while (tmplst->next)
{
if ((*cmp)(*((int *)(tmplst->content)),
*((int *)(tmplst->next->content))))
{
tmpvoid = tmplst->content;
tmpint = tmplst->content_size;
tmplst->content = tmplst->next->content;
tmplst->next->content = tmpvoid;
tmplst->content_size = tmplst->next->content_size;
tmplst->next->content_size = tmpint;
tmplst = lst;
}
else
tmplst = tmplst->next;
}
return (lst);
}