Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** day07 | ||
4 | ** File description: | ||
5 | ** Task06 | ||
6 | */ | ||
7 | |||
8 | #include "my.h" | ||
9 | |||
10 | 14 | static int check_equal(int len_s1, int len_s2, int j, int littlest_char_index) | |
11 | { | ||
12 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
|
14 | if (len_s1 < len_s2) { |
13 | 1 | return j; | |
14 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 11 times.
|
13 | } else if (len_s1 > len_s2) { |
15 | 2 | return littlest_char_index; | |
16 | } else { | ||
17 | 11 | return littlest_char_index; | |
18 | } | ||
19 | } | ||
20 | |||
21 | 18 | static int check_littlest(char **argv, int j, int littlest_char_index) | |
22 | { | ||
23 | 18 | int i = 0; | |
24 | |||
25 | 129 | while (i < my_strlen(argv[littlest_char_index]) | |
26 |
4/4✓ Branch 0 taken 117 times.
✓ Branch 1 taken 12 times.
✓ Branch 3 taken 115 times.
✓ Branch 4 taken 2 times.
|
129 | && i < my_strlen(argv[j])) { |
27 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 112 times.
|
115 | if (argv[littlest_char_index][i] < argv[j][i]) { |
28 | 3 | return j; | |
29 | } | ||
30 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 111 times.
|
112 | if (argv[littlest_char_index][i] > argv[j][i]) { |
31 | 1 | return littlest_char_index; | |
32 | } | ||
33 | 111 | i++; | |
34 | } | ||
35 | 14 | return check_equal(my_strlen(argv[littlest_char_index]), | |
36 | 14 | my_strlen(argv[j]), j, littlest_char_index); | |
37 | } | ||
38 | |||
39 | 9 | static void check_swap(char **argv, int i, int littlest_char_index) | |
40 | { | ||
41 | char *temp; | ||
42 | |||
43 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
|
9 | if (i != littlest_char_index) { |
44 | 4 | temp = argv[i]; | |
45 | 4 | argv[i] = argv[littlest_char_index]; | |
46 | 4 | argv[littlest_char_index] = temp; | |
47 | } | ||
48 | 9 | } | |
49 | |||
50 | 3 | void my_sort_params(int argc, char **argv) | |
51 | { | ||
52 | 3 | int i = 0; | |
53 | 3 | int j = 0; | |
54 | 3 | int littlest_char_index = 0; | |
55 | |||
56 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | for (i = 0; i < argc; i++) { |
57 | 9 | littlest_char_index = i; | |
58 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
|
27 | for (j = i; j < argc; j++) { |
59 | 18 | littlest_char_index = check_littlest(argv, j, littlest_char_index); | |
60 | } | ||
61 | 9 | check_swap(argv, i, littlest_char_index); | |
62 | } | ||
63 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | for (int i = argc; i > 0; i--) { |
64 | 9 | my_putstr(argv[i - 1]); | |
65 | 9 | my_putstr("\n"); | |
66 | } | ||
67 | 3 | } | |
68 |