push_swap/push_swap.c
Etienne Rey-bethbeder 825b4f85b5 Mise a jour V0.2
2022-11-30 20:12:56 +01:00

86 lines
1.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */
/* Updated: 2022/11/30 20:05:21 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "push_swap.h"
#include <stdio.h>
void get_index(int **tab)
{
int i;
int y;
int min;
int old_min;
int new_index;
i = -1;
min = *tab[0];
old_min = *tab[0];
new_index = 0;
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]);
}
}
void push_swap(int *tab, int argc)
{
int *index;
index = malloc(sizeof(int) * (argc + 1));
get_index(&tab);
}
int main(int argc, char *argv[])
{
int *tab;
int i;
int y;
int test;
tab = malloc(sizeof(int) * (argc + 1));
i = 0;
y = 0;
if (argc > 1)
{
while (++i < argc)
{
if(ft_atoi_check(argv[i]))
tab[y++] = ft_atoi(argv[i]);
else
{
write(1, "Error\n", 6);
return (1);
}
}
tab[y] = NULL;
get_index(&tab);
//push_swap(tab, argc);
}
return (0);
}