Mise a jour V0.2

This commit is contained in:
Etienne Rey-bethbeder 2022-11-30 20:12:56 +01:00
parent aa87242f7d
commit 825b4f85b5
3 changed files with 25 additions and 8 deletions

BIN
.push_swap.c.swo Normal file

Binary file not shown.

BIN
.push_swap.c.swp Normal file

Binary file not shown.

View file

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */ /* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/23 16:48:12 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 <stdio.h> #include <stdio.h>
void get_index(int *tab, int **index) void get_index(int **tab)
{ {
int i; int i;
int y;
int min; int min;
int old_min;
int new_index; int new_index;
i = 0; i = -1;
min = tab[0]; min = *tab[0];
old_min = *tab[0];
new_index = 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; int *index;
index = malloc(sizeof(int) * (argc + 1)); index = malloc(sizeof(int) * (argc + 1));
get_index(tab, &index); get_index(&tab);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -61,7 +77,8 @@ int main(int argc, char *argv[])
} }
} }
tab[y] = NULL; tab[y] = NULL;
push_swap(tab, argc); get_index(&tab);
//push_swap(tab, argc);
} }
return (0); return (0);