-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort.c
69 lines (58 loc) · 1.37 KB
/
sort.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
/*
** EPITECH PROJECT, 2021
** B-PSU-100-PAR-1-1-myls-axel.humeau
** File description:
** sort
*/
#include "my_ls.h"
int search_min_time(int i, info_file_t *file)
{
int index_min = i;
for (int j = i; file[j].name != NULL; j++) {
if (file[j].time > file[index_min].time)
index_min = j;
}
return (index_min);
}
void time_sort(info_file_t *file)
{
info_file_t tmp;
int index_min;
for (int i = 0; file[i].name != NULL; i++) {
index_min = search_min_time(i, file);
tmp = file[i];
file[i] = file[index_min];
file[index_min] = tmp;
}
}
int search_min_alpha(int i, info_file_t *file)
{
int index_min = i;
for (int j = i; file[j].name != NULL; j++) {
if (my_strcmp(file[j].name, file[index_min].name) < 0)
index_min = j;
}
return (index_min);
}
void alpha_sort(info_file_t *file)
{
info_file_t tmp;
int index_min;
for (int i = 0; file[i].name != NULL; i++) {
index_min = search_min_alpha(i, file);
tmp = file[i];
file[i] = file[index_min];
file[index_min] = tmp;
}
}
void reverse_sort(info_file_t *file)
{
info_file_t tmp;
int size = 0;
for (; file[size].name != NULL; size++);
for (int i = 0; i < size / 2; i++) {
tmp = file[i];
file[i] = file[size - 1 - i];
file[size - 1 - i] = tmp;
}
}