push_swap/push_swap.c
Etienne Rey-bethbeder 665552486a push
2022-12-04 19:48:24 +01:00

134 lines
2.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/23 16:48:12 by erey-bet #+# #+# */
/* Updated: 2022/12/04 19:48:15 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "push_swap.h"
#include <stdio.h>
int get_min(long *tab, int len)
{
int i;
int index;
i = 0;
index = 0;
while (++i < len)
if (tab[i] <= tab[index])
index = i;
return (index);
}
unsigned int *get_index(long *tab, int len)
{
int i;
int min;
unsigned int *new;
i = -1;
min = tab[0];
new = malloc(sizeof(unsigned int) * (len + 1));
while (++i < len)
{
min = get_min(tab, len);
tab[min] = 2147483648;
new[min] = i;
}
return (new);
}
void swap(t_stack *s)
{
unsigned int c;
c = *s.list[0];
*s.list[0] = *s.list[1];
*s.list[1] = c;
write(1, "sa", 2);
}
void push(t_stack *s_push, t_stack *s_receive, char *message)
{
int i;
int push;
i = 0;
push = *s_push.list[0];
while (++i < *s_push.len)
*s_push.list[i - 1] = *s_push.list[i];
i = 0;
while (++i < *s_receive.len)
{
}
}
void rotate()
{
}
void get_number_in_top(t_stack **s, int y, int len)
{
if (len - y + 1 < len / 2)
}
void push_swap(long *tab, int len)
{
int i;
int y;
t_stack sa;
t_stack sb;
sa.list = get_index(tab, len);
sa.len = len;
sb.list = malloc(sizeof(unsigned int) * (len + 1));
sb.len = 0;
i = 0;
y = 1;
while (i < len)
{
if ((sa.list[i] >> y) & 1 == 1)
{
if (i > 0)
// get number in top
}
}
}
int main(int argc, char *argv[])
{
long *tab;
int i;
int y;
i = 0;
y = 0;
tab = malloc(sizeof(long) * (argc + 1));
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);
}
}
get_index(tab, y);
}
return (0);
}