This repository has been archived by the owner on Jan 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ordering.c
89 lines (82 loc) · 2.53 KB
/
ordering.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ordering.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: arizzell <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/17 11:26:15 by arizzell #+# #+# */
/* Updated: 2017/12/17 11:26:16 by arizzell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
static void lst_swap(t_object *p1, t_object *p2)
{
struct stat lstats;
struct dirent name;
char lkname[255];
lstats = p1->lstats;
name = p1->name;
ft_strcpy(lkname, p1->lkname);
p1->lstats = p2->lstats;
p1->name = p2->name;
ft_strcpy(p1->lkname, p2->lkname);
p2->lstats = lstats;
p2->name = name;
ft_strcpy(p2->lkname, lkname);
}
t_object *lst_sort_ascii(t_object *lst)
{
if (!lst)
return (NULL);
if (lst->next && ft_strcmp(lst->name.d_name, lst->next->name.d_name) > 0)
lst_swap(lst, lst->next);
lst->next = lst_sort_ascii(lst->next);
if (lst->next && ft_strcmp(lst->name.d_name, lst->next->name.d_name) > 0)
{
lst_swap(lst, lst->next);
lst->next = lst_sort_ascii(lst->next);
}
return (lst);
}
t_object *ft_dataorder(t_object *list)
{
if (!list)
return (NULL);
if (list->next && (list->MODE.tv_sec < list->next->MODE.tv_sec))
lst_swap(list, list->next);
else if (list->next && list->MODE.tv_sec == list->next->MODE.tv_sec)
if (list->next && (list->MODE.tv_nsec < list->next->MODE.tv_nsec))
lst_swap(list, list->next);
list->next = ft_dataorder(list->next);
if (list->next && (list->MODE.tv_sec < list->next->MODE.tv_sec))
{
lst_swap(list, list->next);
list->next = ft_dataorder(list->next);
}
else if (list->next && list->MODE.tv_sec == list->next->MODE.tv_sec)
{
if (list->next && (list->MODE.tv_nsec < list->next->MODE.tv_nsec))
{
lst_swap(list, list->next);
list->next = ft_dataorder(list->next);
}
}
return (list);
}
t_object *ft_reverseorder(t_object *list)
{
t_object *a;
t_object *b;
t_object *c;
a = NULL;
b = list;
while (b)
{
c = b->next;
b->next = a;
a = b;
b = c;
}
return (a);
}