From: Lukas Jiriste Date: Wed, 28 Jun 2023 08:22:50 +0000 (+0200) Subject: Solution to Ex. 07. X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=245a249d7adb0e2d66e6f6ffd71b82173d8dc12a;p=42%2FC_11.git Solution to Ex. 07. --- diff --git a/ex07/ft_advanced_sort_string_tab.c b/ex07/ft_advanced_sort_string_tab.c new file mode 100644 index 0000000..c2a7779 --- /dev/null +++ b/ex07/ft_advanced_sort_string_tab.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_advanced_sort_string_tab.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ljiriste +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/06/28 07:13:52 by ljiriste #+# #+# */ +/* Updated: 2023/06/28 10:21:06 by ljiriste ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(char **s1, char **s2) +{ + char *temp; + + temp = *s1; + *s1 = *s2; + *s2 = temp; + return ; +} + +void ft_advanced_sort_string_tab(char **tab, int (*cmp)(char *, char *)) +{ + int i; + int j; + + if (!*tab) + return ; + i = 0; + while (tab[i + 1]) + { + j = i + 1; + while (tab[j]) + { + if (cmp(tab[i], tab[j]) > 0) + ft_swap(tab + i, tab + j); + ++j; + } + ++i; + } + return ; +}