-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_sort.c
More file actions
57 lines (52 loc) · 1.69 KB
/
list_sort.c
File metadata and controls
57 lines (52 loc) · 1.69 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_sort.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbeaufre <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/15 15:46:21 by rbeaufre #+# #+# */
/* Updated: 2019/11/27 18:34:46 by rbeaufre ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
void ft_list_sort_asc_by_name(t_list **list)
{
t_list *tmp;
t_list *tmp2;
t_node *node;
t_node *node2;
t_node *node3;
tmp = *list;
while (tmp)
{
tmp2 = *list;
while (tmp2 && tmp2->content && tmp2->next && tmp2->next->content)
{
node = (t_node *)tmp2->content;
node2 = ((t_node *)tmp2->next->content);
if (ft_strcmp(node->name, node2->name) > 0)
{
node3 = tmp2->content;
tmp2->content = tmp2->next->content;
tmp2->next->content = node3;
}
tmp2 = tmp2->next;
}
tmp = tmp->next;
}
}
void ft_list_sort_adj(t_list **list)
{
t_list *tmp;
t_list *to_sort;
t_node *node;
tmp = *list;
while (tmp && tmp->content && ((t_node *)tmp->content)->next)
{
node = ((t_node *)tmp->content);
to_sort = node->next;
ft_list_sort_asc_by_name(&to_sort);
tmp = tmp->next;
}
}