diff --git a/.push_swap.c.swo b/.push_swap.c.swo new file mode 100644 index 0000000..d3916d9 Binary files /dev/null and b/.push_swap.c.swo differ diff --git a/.push_swap.c.swp b/.push_swap.c.swp new file mode 100644 index 0000000..c8c8614 Binary files /dev/null and b/.push_swap.c.swp differ diff --git a/push_swap.c b/push_swap.c index 5eff4cd..5d575c0 100644 --- a/push_swap.c +++ b/push_swap.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */ -/* Updated: 2022/11/27 23:10:27 by erey-bet ### ########.fr */ +/* Updated: 2022/11/30 20:05:21 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,18 +15,34 @@ #include -void get_index(int *tab, int **index) +void get_index(int **tab) { int i; + int y; int min; + int old_min; int new_index; - i = 0; - min = tab[0]; + i = -1; + min = *tab[0]; + old_min = *tab[0]; new_index = 0; - while (i < argc) + while (*tab[++i] != NULL) { - + y = -1; + while (*tab[++y] != NULL) + { + if (*tab[y] < min && *tab[y] <= old_min) + { + min = *tab[y]; + *tab[y] = new_index++; + } + old_min = min; + } + } + for (i = 0 ; tab[i] != NULL ; i++) + { + printf("%d", tab[i]); } } @@ -35,7 +51,7 @@ void push_swap(int *tab, int argc) int *index; index = malloc(sizeof(int) * (argc + 1)); - get_index(tab, &index); + get_index(&tab); } int main(int argc, char *argv[]) @@ -61,7 +77,8 @@ int main(int argc, char *argv[]) } } tab[y] = NULL; - push_swap(tab, argc); + get_index(&tab); + //push_swap(tab, argc); } return (0);