blob: c3d0391c930dbaa817ef0833bf935f0527240935 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsorted_merge.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/10 01:58:52 by cacharle #+# #+# */
/* Updated: 2020/02/10 02:13:37 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft_lst.h"
t_ftlst *ft_lstsorted_merge(t_ftlst *l1, t_ftlst *l2,
int (*cmp)(void *, void *))
{
t_ftlst *merged;
merged = NULL;
if (l1 == NULL)
return (l2);
if (l2 == NULL)
return (l1);
if (cmp(l1->content, l2->content) < 0)
{
merged = l1;
merged->next = ft_lstsorted_merge(l1->next, l2, cmp);
}
else
{
merged = l2;
merged->next = ft_lstsorted_merge(l1, l2->next, cmp);
}
return (merged);
}
|