-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorts.c
123 lines (114 loc) · 2.88 KB
/
sorts.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sorts.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dmoureu- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/07 19:04:44 by dmoureu- #+# #+# */
/* Updated: 2016/02/07 19:08:24 by dmoureu- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
t_arg *sortargs(t_arg *lst, int (*cmp)(char *, char *))
{
t_arg *tmparg;
t_ent *tmpent;
char *tmpstr;
time_t tmptime;
tmparg = lst;
while (tmparg->next)
{
if ((*cmp)(tmparg->path, tmparg->next->path) <= 0)
tmparg = tmparg->next;
else
{
tmpent = tmparg->ent;
tmpstr = tmparg->path;
tmptime = tmparg->mtime;
tmparg->ent = tmparg->next->ent;
tmparg->path = tmparg->next->path;
tmparg->mtime = tmparg->next->mtime;
tmparg->next->ent = tmpent;
tmparg->next->path = tmpstr;
tmparg->next->mtime = tmptime;
tmparg = lst;
}
}
return (lst);
}
t_arg *sortargstime(t_arg *lst, int (*cmp)(time_t, time_t))
{
t_arg *tmparg;
t_ent *tmpent;
char *tmpstr;
time_t tmptime;
tmparg = lst;
while (tmparg->next)
{
if ((*cmp)(tmparg->mtime, tmparg->next->mtime) <= 0)
tmparg = tmparg->next;
else
{
tmpent = tmparg->ent;
tmpstr = tmparg->path;
tmptime = tmparg->mtime;
tmparg->ent = tmparg->next->ent;
tmparg->path = tmparg->next->path;
tmparg->mtime = tmparg->next->mtime;
tmparg->next->ent = tmpent;
tmparg->next->path = tmpstr;
tmparg->next->mtime = tmptime;
tmparg = lst;
}
}
return (lst);
}
t_ent *sortents(t_ent *lst, int (*cmp)(char *, char *))
{
t_ent *tmp;
char *tmpstr;
int time;
tmp = lst;
while (tmp->next)
{
if ((*cmp)(tmp->name, tmp->next->name) <= 0)
tmp = tmp->next;
else
{
tmpstr = tmp->name;
time = tmp->mtime;
tmp->name = tmp->next->name;
tmp->mtime = tmp->next->mtime;
tmp->next->mtime = time;
tmp->next->name = tmpstr;
tmp = lst;
}
}
lst = tmp;
return (lst);
}
t_ent *sortentstime(t_ent *lst, int (*cmp)(time_t, time_t))
{
t_ent *tmp;
char *tmpstr;
int time;
tmp = lst;
while (tmp->next)
{
if ((*cmp)(tmp->mtime, tmp->next->mtime) <= 0)
tmp = tmp->next;
else
{
tmpstr = tmp->name;
time = tmp->mtime;
tmp->name = tmp->next->name;
tmp->mtime = tmp->next->mtime;
tmp->next->mtime = time;
tmp->next->name = tmpstr;
tmp = lst;
}
}
lst = tmp;
return (lst);
}