aboutsummaryrefslogtreecommitdiff
path: root/c11/ex07
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-07-19 07:04:04 +0200
committerCharles <sircharlesaze@gmail.com>2019-07-19 07:04:04 +0200
commit8b6e91bdb56bc01a588718472546f2a88e750b48 (patch)
tree654ba9e8216c688bb3d6a2e5d67526ae8ec4b874 /c11/ex07
parent880102ae9358db130ef67cc9a7177a1e1de76875 (diff)
downloadpiscine-8b6e91bdb56bc01a588718472546f2a88e750b48.tar.gz
piscine-8b6e91bdb56bc01a588718472546f2a88e750b48.tar.bz2
piscine-8b6e91bdb56bc01a588718472546f2a88e750b48.zip
c10 done?, c11 moulinetted (ex04, ex06 need correction)
Diffstat (limited to 'c11/ex07')
-rw-r--r--c11/ex07/ft_advanced_sort_string_tab.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/c11/ex07/ft_advanced_sort_string_tab.c b/c11/ex07/ft_advanced_sort_string_tab.c
index f640664..efcfb37 100644
--- a/c11/ex07/ft_advanced_sort_string_tab.c
+++ b/c11/ex07/ft_advanced_sort_string_tab.c
@@ -6,39 +6,41 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/16 21:51:06 by cacharle #+# #+# */
-/* Updated: 2019/07/16 21:54:24 by cacharle ### ########.fr */
+/* Updated: 2019/07/18 11:03:31 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-int is_sorted(char **tab, int(*cmp)(char *, char *))
+#include <stdlib.h>
+
+int sorted(char **tab, int (*cmp)(char *, char *))
{
int i;
- i = 1;
- while (tab[i] != NULL)
+ i = 0;
+ while (tab[i + 1] != NULL)
{
- if ((*cmp)(tab[i], tab[i +1]) > 0)
+ if ((*cmp)(tab[i], tab[i + 1]) > 0)
return (0);
i++;
}
return (1);
}
-void ft_advanced_sort_string_tab(char **tab, int(*cmp)(char *, char *))
+void ft_advanced_sort_string_tab(char **tab, int (*cmp)(char *, char *))
{
int i;
char *tmp;
- while (!is_sorted(tab))
+ while (!sorted(tab, cmp))
{
- i = 1;
- while (tab[i] != NULL)
+ i = 0;
+ while (tab[i + 1] != NULL)
{
- if ((*cmp)(tab[i], tab[i +1]) > 0)
+ if ((*cmp)(tab[i], tab[i + 1]) > 0)
{
- tmp = argv[i];
- argv[i] = argv[i + 1];
- argv[i + 1] = tmp;
+ tmp = tab[i];
+ tab[i] = tab[i + 1];
+ tab[i + 1] = tmp;
}
i++;
}