Exemplo n.º 1
0
void		action_pile_a(t_dbl **a, int i, t_dbllist **lstactions)
{
	int		pos;

	pos = 0;
	i = ft_min_pile(*a, &pos);
	if ((*a)->tail->prev && i == (*a)->tail->prev->value)
	{
		ft_swap_pile(a);
		ft_lstdbladd(lstactions, "sa", 3);
	}
	else if (pos > (int)(*a)->length / 2)
	{
		while ((*a)->tail->value != i)
		{
			ft_rot_pile(a);
			ft_lstdbladd(lstactions, "ra", 3);
		}
	}
	else
	{
		while ((*a)->tail->value != i)
		{
			ft_rev_rot_pile(a);
			ft_lstdbladd(lstactions, "rra", 4);
		}
	}
}
Exemplo n.º 2
0
void		action_fusion(t_dbl **b, int i, t_dbllist **lstactions)
{
	int		pos;

	i = ft_max_pile(*b, &pos);
	if ((*b)->tail->prev && i == (*b)->tail->prev->value)
	{
		ft_swap_pile(b);
		ft_lstdbladd(lstactions, "sb", 3);
	}
	else if (pos > (int)(*b)->length / 2)
	{
		while ((*b)->tail->value != i)
		{
			ft_rot_pile(b);
			ft_lstdbladd(lstactions, "rb", 3);
		}
	}
	else
	{
		while ((*b)->tail->value != i)
		{
			ft_rev_rot_pile(b);
			ft_lstdbladd(lstactions, "rrb", 4);
		}
	}
}
Exemplo n.º 3
0
int		split_arg(const char *format, t_dbllist *lst_arg, t_dbllist *lst_str,
		int *i)
{
	t_arg		sarg;
	t_str		sstr;
	int			ret;

	ini_sarg(&sarg);
	ini_sstr(&sstr);
	if ((ret = checks(format, i, &sarg)) == -1)
		return (-1);
	*i = *i + 1;
	if (ret == -2)
	{
		ft_lstdbladd(lst_arg, &sarg, sizeof(t_arg));
		sstr.str = ft_strdup(sarg.spec);
		ft_lstdbladd(lst_str, &sstr, sizeof(t_str));
		recover_arg(format, lst_arg, lst_str, i);
	}
	else
	{
		ft_lstdbladd(lst_arg, &sarg, sizeof(t_arg));
		sstr.str = ft_strdup(sarg.spec);
		ft_lstdbladd(lst_str, &sstr, sizeof(t_str));
		if (format[*i] != '\0')
			recover_arg(format, lst_arg, lst_str, i);
	}
	return (1);
}
Exemplo n.º 4
0
void		push_swap(t_dbl **a, t_dbl **b, t_option option,
	t_dbllist **lstactions)
{
	int		i;
	int		nb_push;

	nb_push = 0;
	while (!list_rev_ok(*a))
	{
		action_pile_a(a, i, lstactions);
		if (!list_rev_ok(*a))
		{
			ft_push_pile(a, b);
			ft_lstdbladd(lstactions, "pb", 3);
			nb_push++;
		}
		if (option.v)
		{
			if (option.c)
				ft_affiche_color(*a, *b, 0);
			else
				ft_affiche(*a, *b);
		}
	}
	action_pile_b(a, b, nb_push, lstactions);
}
Exemplo n.º 5
0
void		action_pile_b(t_dbl **a, t_dbl **b, int nb_push,
	t_dbllist **lstactions)
{
	while (nb_push != 0)
	{
		ft_push_pile(b, a);
		ft_lstdbladd(lstactions, "pa", 3);
		nb_push--;
	}
}
Exemplo n.º 6
0
void		push_swap2(t_dbl **a, t_dbl **b, t_option option,
	t_dbllist **lstactions)
{
	int		i;

	while ((*b)->length != 0)
	{
		action_fusion(b, i, lstactions);
		ft_push_pile(b, a);
		ft_lstdbladd(lstactions, "pa", 3);
		push_swap(a, b, option, lstactions);
		if (option.v)
		{
			if (option.c)
				ft_affiche_color(*a, *b, 0);
			else
				ft_affiche(*a, *b);
		}
	}
}